I am importing data from a keyed table in Kdb+ to a pandas DataFrame using qPython library. If I run a synchronous query
x=q.sync('select from prod where ID=9 ')
Then x is of type qpython.qcollection.QKeyedTable
. But if I make numpy_temporals=true
the return type is pandas 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] returns
EMP_ID PROD_ID month total x
01 02 jan-17 5.5 6
x.columns.values returns
['month' 'total' 'x']
The data is from a keyed table, the DataFrame is unable to access the primary key fields. The table has 5 fields but the returned data frame shows only 3. I am unable to access the first two columns.
I have looked at the following stackoverflow questions Not able to view all columns in Pandas Data frame, Python pandas, how to widen output display to see more columns? but they do not solve the problem.
Also I want to read the data from the DataFrame into a class Employee
, so as to create a feature vector for each employee. I do not want the data to be stored in a DataFrame as certain features will be multi-valued like organization
(the employee might work part-time in multiple organizations).
Am I doing it correctly or is there a better way to solve this problem.