exxeleron/qPython
模块允许将 pandas 发送DataFrame
到kdb+/q
's 表。
让我们准备数据:
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
DataFrame
然后要传递的对象如下所示:
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
当我尝试将其发送到 时kdb+/q
,我收到以下错误:
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