简体   繁体   English

在 Python 3.8 中使用 qPython 和 Pandas 在 q-lang 中查询

[英]Query in q-lang using qPython and Pandas in Python 3.8

I am totally new to q-language, but I need to use it in order to access a kdb server to get the data from.我对 q-language 完全陌生,但我需要使用它来访问 kdb 服务器以从中获取数据。

I am using Python 3.8, under Windows10, with qPython installed.我在 Windows10 下使用 Python 3.8,并安装了 qPython。

I have trouble getting the query to the server.我无法将查询发送到服务器。

from qpython import qconnection
import pandas as pd


tbl = 'q("h\"select from trade where date = 2007.02.28, sym = `XXXX\"")'


q = qconnection.QConnection(host=server, port=server_port, username=user, password=server_password, timeout=server_timeout)

q.open()
df = pd.DataFrame(q.sendSync('tbl'))
q.close()

On executing the script it returns an error at line 15:在执行脚本时,它在第 15 行返回一个错误:

qpython.qtype.QException: b'tbl'

So I have a trouble sending the correct expression to the server.所以我无法将正确的表达式发送到服务器。 I was able to pass the expression via terminal, using q (with PyQ) under Linux Debian 10, so the query is correct.我能够通过终端传递表达式,在 Linux Debian 10 下使用 q(使用 PyQ),所以查询是正确的。

(The server details are skipped, as well as the bond name). (跳过服务器详细信息以及绑定名称)。

PyQ and qPython are being confused here. PyQ 和 qPython 在这里被混淆了。 q.sendSync('tbl') will get the variable tbl from the kdb server. q.sendSync('tbl')将从 kdb 服务器获取变量 tbl。 This error: qpython.qtype.QException: b'tbl' means tbl doesn't exist on the kdb server.此错误: qpython.qtype.QException: b'tbl'表示 kdb 服务器上不存在 tbl。 I think what you wanted is the select statement to be sent to the kdb server:我认为您想要的是要发送到 kdb 服务器的 select 语句:

from qpython import qconnection
import pandas as pd

q = qconnection.QConnection(host=server, port=server_port, username=user, password=server_password, timeout=server_timeout, pandas=True)

q.open()
df = q.sendSync('select from trade where date = 2007.02.28, sym = `XXXX')
q.close()

It might be worth while for you to spend sometime with q itself and get up to speed with some basics here:花点时间了解 q 本身并快速了解一些基础知识可能是值得的:

https://code.kx.com/q4m3/1_Q_Shock_and_Awe/ https://code.kx.com/q4m3/1_Q_Shock_and_Awe/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM