将pandas数据帧保存在kdb/q中

Nic*_*ick 1 kdb pandas

在kdb中保存pandas数据帧的最佳方法是什么?有没有可以让它更容易的库?

下面的代码显然可以用来从kdb中获取一些东西,但是如何将数据框保存到它中呢?

from qpython import qconnection

with qconnection.QConnection(host = 'localhost', port = 5001, pandas = True) as q:
    ds = q('(1i;0Ni;3i)', pandas = True)
    print(ds)
Run Code Online (Sandbox Code Playgroud)

小智 5

使用Pandas Integration的模拟表

with qconnection.QConnection(host = 'localhost', port = 5000, pandas = True) as q:

 df =  q('flip `name`iq`fullname!(`Dent`Beeblebrox`Prefect;98 42 126;("Arthur Dent";"Zaphod Beeblebrox"; "Ford Prefect"))')
Run Code Online (Sandbox Code Playgroud)

这将一个在kdb中构建的表作为pandas数据帧拉回到python中.以下方法将表保存在内存中:

with qconnection.QConnection(host = 'localhost', port = 5000, pandas = True) as q:

  q('{`t set x}', df)
Run Code Online (Sandbox Code Playgroud)

可以找到有关如何在kdb中保存数据的更多信息:kdb概述

可以在此处找到使用set来保存数据的更多示例:set

还有另一种集成python和q的方法,可能对你有用; PyQ将Python和q解释器带入同一个进程,因此用任一语言编写的代码都在相同的数据上运行.