【问题标题】:KDB+ query in QPython: Filter based on DataFrame listQPython 中的 KDB+ 查询:基于 DataFrame 列表的过滤器
【发布时间】:2018-09-10 10:47:13
【问题描述】:

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

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 个问题,请忽略第二个问题。在那种情况下道歉。

谢谢!

【问题讨论】:

    标签: python kdb qpython


    【解决方案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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-22
      相关资源
      最近更新 更多