【发布时间】:2015-09-30 05:07:57
【问题描述】:
我想每天从 HUGE hdf5 中选择一个数据子集。使用where mask 将是完美的,但我不能使它与多索引一起使用(因为我必须有两个条件的位置)。不能使用带有多索引的 where 掩码:
import itertools
import pandas as pd
import numpy as np
a = ('A', 'B')
i = (0, 1, 2)
idx = pd.MultiIndex.from_tuples(list(itertools.product(a, i)),
names=('Alpha', 'Int'))
df = pd.DataFrame(np.random.randn(len(idx), 7), index=idx,
columns=('I', 'II', 'III', 'IV', 'V', 'VI', 'VII'))
好的,现在我把它放在 hdf 商店里
from pandas.io.pytables import HDFStore
store =HDFStore('cancella.h5', 'w')
store.append('df_mask',df)
但如果我再读一遍,我有
c = store.select_column('df_mask','index')
print c
这个索引是错误的。
0 0
1 1
2 2
3 3
4 4
5 5
dtype: int64
所以我不能使用where mask。你能帮帮我吗?
【问题讨论】: