exxeleron/qPython
module allows to send the pandas DataFrame
to kdb+/q
's table.
Let's prepare the data:
import pandas.io.data as web
import datetime
import numpy
start = datetime.datetime(2010, 1, 1)
end = datetime.datetime(2015, 2, 6)
f = web.DataReader(["F","MSFT"], 'yahoo', start, end) # download stock data from Yahoo Finance
f = f.to_frame().reset_index() # flatten the MultiIndex to have a sym column, see below
f = f[["Date","minor","Close"]]
f.columns = ["dt","sym","val"] # just give comfortable names
The DataFrame
object to be passed then looks like:
f.head()
# Out:
# dt sym val
# 0 2010-01-04 F 10.28
# 1 2010-01-04 MSFT 30.95
# 2 2010-01-05 F 10.96
# 3 2010-01-05 MSFT 30.96
# 4 2010-01-06 F 11.37
f.dtypes
# Out:
# dt datetime64[ns]
# sym object
# val float64
When I try to send it to kdb+/q
, I get the following error:
import qpython.qconnection as qconnection
q = qconnection.QConnection(host = 'localhost', port = 5000, pandas = True)
q.open()
q('set', numpy.string_('tbl'), f)
# File "G:\Anaconda\lib\site-packages\qpython\_pandas.py", line 159, in _write_pandas_series
# data = data.fillna(QNULLMAP[-abs(qtype)][1])
# KeyError: -10