我使用的是Python2.7,我已经在Debian10下安装了PyQ,Q (x64版本)设置正确。
问题是如何连接到KDB服务器(我有凭据(IP、端口、用户和密码))?
发布于 2020-02-14 20:45:44
启动pyq会话,切换到Q解释器,然后使用hopen
Using the q interpreter in PyQ:
>>> q()
q)h:hopen `:localhost:1234 // `:host:port:user:pass
q)h"2+2"
q)4编辑-来自Python和Creating A Pandas.DataFrame的进一步示例:
I have the following table defined on my q server process:
q)tbl:([]col1:`a`b`c;col2:til 3)
q)tbl
col1 col2
---------
a 0
b 1
c 2
Then from my client PyQ interpreter:
from pyq import q
import numpy as np # Numpy is needed as a middle man for interpreting kdb objects to python.
import pandas as pd
import datetime # if your kdb table has dates and times
q("h:hopen `:localhost:1234")
tbl2 = q("h\"tbl\"") # need to escape the quotes around tbl
tblNP = np.array(tbl2)
df = pd.DataFrame(tblNP)
df
col1 col2
0 a 0
1 b 1
2 c 2使用qPython:
from qpython import qconnection
import pandas as pd
if __name__ == '__main__':
# create connection object
q = qconnection.QConnection(host='localhost', port=1234, pandas=True)
# initialize connection
q.open()
# simple query execution via: QConnection.sendSync
df = q.sendSync('tbl')
# close connection
q.close()有关如何从表中选择特定数据的信息,请参阅qSQL。kdb中的表可能非常大,选择整个表可能是不明智的。情商。
PyQ:
tbl2 = q("h\"select from trades where date = 2020.02.14\"")
qPython:
df = q.sendSync('select from trades where date = 2020.02.14')你打算在q中做任何数据处理客户端吗?如果只想从kdb服务器获取数据以便与python一起使用,qPython可能是更好的选择。
https://stackoverflow.com/questions/60226208
复制相似问题