QPython中的KDB +查询:根据DataFrame列表进行过滤

时间:2018-09-10 10:47:14

标签: python kdb qpython

我正在使用qpython查询到KDB +数据库,然后对输出执行操作。 old_df是从早期的qpython同步查询输出的,该查询以'[source_id]'作为字符串列。现在正在查询另一个数据库trades_database,该数据库具有相同的字段(与source_id),但具有不同的列名customer(也是字符串,数据类型没有问题)

params = np.array([])
for i in old_df['source_id']:
    params = np.append(params, np.string_(i))

new_df = q.sync('{[w]select from trade_database where customer in w}', *params, pandas=True)

不幸的是,在线解决此类查询的渠道很少。我从这里提出的问题中学到了很多东西,但确实陷在这里。我的列表可能很长,因此需要编写一个查询,仅将其作为输入。

我也尝试过:

new_df= q1.sync('{select from trades_database where customer in (`1234, `ABCD)}', pandas=True)

可以用,但是我知道 <qpython.qtype.QLambda object at 0x000000000413F710>

一个人如何解压缩QLambda对象?

如果不允许我在同一篇文章中问2个问题,请忽略第二个问题。在这种情况下道歉。

谢谢!

1 个答案:

答案 0 :(得分:1)

这是我所做的,并且似乎可以正常工作:

    params = np.array(one_id) #just input the initial id used to search for old_df, and not put the square brackets to make it into a list

    for i in old_df['source_id']:
        params = np.append(params,np.string_(i))
    params=np.unique(params)

    new_df = q1.sync('{[w]select from trades_database where customer in w}', params, pandas=True)