Return KDB 查询 pandas 数据框
Return KDB query to a pandas datframe
我想从 KDB 数据库中提取数据并将其放入 datframe 中。我的查询在 qpad 中运行良好,没有问题;只需要将它写入我的 Pandas 数据框。我的代码:
from qpython import qconnection
# Create the connection and save the handle to a variable
q = qconnection.QConnection(host = 'wokplpaxvj003', port = 11503, username = 'pelucas', password = 'Dive2600', timeout = 3.0)
try:
# initialize connection
q.open()
print(q)
print('IPC version: %s. Is connected: %s' % (q.protocol_version, q.is_connected()))
df = q.sendSync('{select from quote_flat where date within (2019.08.14;2019.08.14), amendment_no = (max;amendment_no)fby quote_id}')
df.info()
finally:
q.close()
它在 df.info()
引发 AttributeError: 'QLambda' object has no attribute 'info'
时失败,所以我猜调用没有成功。
您似乎只发送了一个 lambda,但没有执行该 lambda 的指令。两个选项:
- 不要让它成为 lambda
df = q.sendSync('select from quote_flat where date within (2019.08.14;2019.08.14), amendment_no = (max;amendment_no)fby quote_id')
- 执行 lambda
df = q.sendSync('{select from quote_flat where date within (2019.08.14;2019.08.14), amendment_no = (max;amendment_no)fby quote_id}[]')
我想从 KDB 数据库中提取数据并将其放入 datframe 中。我的查询在 qpad 中运行良好,没有问题;只需要将它写入我的 Pandas 数据框。我的代码:
from qpython import qconnection
# Create the connection and save the handle to a variable
q = qconnection.QConnection(host = 'wokplpaxvj003', port = 11503, username = 'pelucas', password = 'Dive2600', timeout = 3.0)
try:
# initialize connection
q.open()
print(q)
print('IPC version: %s. Is connected: %s' % (q.protocol_version, q.is_connected()))
df = q.sendSync('{select from quote_flat where date within (2019.08.14;2019.08.14), amendment_no = (max;amendment_no)fby quote_id}')
df.info()
finally:
q.close()
它在 df.info()
引发 AttributeError: 'QLambda' object has no attribute 'info'
时失败,所以我猜调用没有成功。
您似乎只发送了一个 lambda,但没有执行该 lambda 的指令。两个选项:
- 不要让它成为 lambda
df = q.sendSync('select from quote_flat where date within (2019.08.14;2019.08.14), amendment_no = (max;amendment_no)fby quote_id')
- 执行 lambda
df = q.sendSync('{select from quote_flat where date within (2019.08.14;2019.08.14), amendment_no = (max;amendment_no)fby quote_id}[]')