无法访问从kdb+;导入数据的数据框中的所有列;使用qPython

无法访问从kdb+;导入数据的数据框中的所有列;使用qPython,python,pandas,dataframe,kdb,Python,Pandas,Dataframe,Kdb,我正在使用qPython库将数据从Kdb+中的键控表导入pandas数据帧。如果我运行同步查询 x=q.sync('select from prod where ID=9 ') 那么x的类型是qpython.qcollection.QKeyedTable。但是如果我使numpy\u temporals=true返回类型为DataFrame from qpython import qconnection with qconnection.QConnection(host

我正在使用qPython库将数据从Kdb+中的键控表导入pandas数据帧。如果我运行同步查询

    x=q.sync('select from prod where ID=9 ') 
那么x的类型是
qpython.qcollection.QKeyedTable
。但是如果我使
numpy\u temporals=true
返回类型为DataFrame

    from qpython import qconnection
    with qconnection.QConnection(host = 'localhost', port = 5000) as q:
    query = 'select from table where ID=5'
    x=q.sync(query, numpy_temporals = True)
    print x.iloc[0:3,0:3]
    print x.columns.values
x、 iloc[0:1,0:1]返回

EMP_ID   PROD_ID   month   total   x 
01        02       jan-17    5.5   6
x、 columns.values返回值

['month' 'total' 'x']
数据来自键控表,DataFrame无法访问主键字段。该表有5个字段,但返回的数据框仅显示3个字段。我无法访问前两列

我已经研究了以下stackoverflow问题,但它们并不能解决问题

我还想将数据帧中的数据读入一个类
Employee
,以便为每个Employee创建一个特征向量。我不希望数据存储在数据框中,因为某些功能将是多值的,如
组织
(员工可能在多个组织中兼职)


我做得对吗,还是有更好的方法来解决这个问题。

您看到的是一个键控表-转换为数据帧使键成为表的索引-

Q过程

q)\p 5000
q)t:([a:til 10;b:reverse til 10]c:10?`3;d:10?10i)
Python进程

> import pandas as pd
> import numpy as np
> from qpython.qconnection import QConnection as qc
> q = qc('localhost', 5000)
> q.open()
> x = q.sync('select from t', pandas=True)
> x.columns.values
array(['c', 'd'], dtype=object)
> x.index
MultiIndex(levels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]],
       labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]],
       names=[u'a', u'b'])
如果希望将所有列作为标准数据框查看,而不使用索引(标准i索引除外),请将查询修改为

> x = q.sync('0!select from t', pandas=True) 
注意
0执行的取消锁定

> x.columns.values
array(['a', 'b', 'c', 'd'], dtype=object)
这本书值得一读,因为它确实涵盖了这一点