我有一个巨大的HDF5文件,我想把它的一部分加载到pandas数据框中来执行一些操作,但是我对过滤一些行很感兴趣。
我可以用一个例子来更好地解释:
原始HDF5文件看起来像:
A B C D
1 0 34 11
2 0 32 15
3 1 35 22
4 1 34 15
5 1 31 9
1 0 34 15
2 1 29 11
3 0 34 15
4 1 12 14
5 0 34 15
1 0 32 13
2 1 34 15
etc etc etc etc
我要做的是将它加载到pandas数据框中,但只加载where A==1 or 3 or 4
到目前为止,我可以使用以下命令加载整个HDF5:
store = pd.HDFStore('Resutls2015_10_21.h5')
df = pd.DataFrame(store['results_table'])
我不知道如何在这里包含where
条件。
hdf5
文件必须以^{fixed
格式相反)格式写入 使用pd.read_hdf
的where
参数可查询。此外,
A
必须是declared as a data_column:或者,要将所有列指定为(可查询的)数据列:
那你就可以用
选择值列
A
为1、3或4的行。例如收益率
如果您有一个很长的值列表
vals
,那么可以使用字符串格式来组成右where
参数:您可以使用
pandas.read_hdf
(here)和可选参数where
来完成此操作。对于example:
read_hdf('store_tl.h5', 'table', where = ['index>2'])
相关问题 更多 >
编程相关推荐