熊猫HDFStore.select在MultiIndex数据帧上

时间:2019-06-20 10:14:38

标签: python pandas hdf5 numexpr

我正在尝试使用pd.HDFStore.select方法,使用where关键字参数指定的条件来加载HDFStore中存储的数据帧的子集。

由于MemoryError,加载整个数据帧并随后使用df.query失败。

存储的数据帧(称为shotsTof)具有以下结构:

                  0     1     2     3   ....
pulseId  shotNum
72304631 0        -7   -12   -14   -23  
         2        -2    -5     1    10 
         4        -4    -1     0    -1 
         ⋮
72304632 0        -5   -10    -9    -8  
         2        -29   -25   -12    1
         4        -7    -6     0     0
         ⋮

我已经尝试过像这样过滤,其中group.index是具有与shotsTof相同结构的multiIndex:

store.select('shotsTof',  where='index in group.index')

并为:

store.select('shotsTof',  where='(pulseId, shotsNum) in group.index')

但均以TypeError: float() argument must be a string or a number, not 'tuple'

失败

我还尝试过像这样“展平” multiIndex(以便将索引(72304631, 4)映射到7230463104):

    idx = group.index.get_level_values(0) * 100 + group.index.get_level_values(1)
    shotsTof  = store.select('shotsTof',  where='(pulseId*100 + shotNum) in idx')

但是我得到NotImplementedError: unsupported operand types for *and*: bool, long

有人可以帮助我理解此错误或提出更好的方法来实现我想要实现的目标吗?

谢谢!

0 个答案:

没有答案