【发布时间】:2017-03-11 14:48:14
【问题描述】:
我使用以下 Python/Pandas 代码从 HDF 表中读取行的随机子集:
hdf_store = pd.HDFStore('path_to_data.h5')
total_rows = hdf_store.get_storer('hdf_table_name').nrows
num_rows = int(total_rows * .25)
row_indices = np.random.randint(0,rows_indices,size=num_rows)
my_df = pd.read_hdf(hdf_store, 'hdf_table_name', where=pd.Index(row_indices))
稍后在程序中,我想从 HDF5 表中提取其余的数据行。但以下引发了错误:
rest_of_rows = pd.read_hdf(hdf_store, 'hdf_table_name',
where=pd.Index(not in (row_indices)))
rest_of_rows = pd.read_hdf(hdf_store, 'hdf_table_name',
where=not pd.Index(row_indices))
有没有办法通过不在索引列表中的记录来提取 HDF 行?
由于该表比我的 RAM 大,我想避免预先从 HDF 中提取所有行(即使是块),然后将其拆分以同时保存两个表。我可以将索引映射到另一列,以及不在该列映射值中的行的子集。但这大概比直接查询索引要慢很多。
【问题讨论】:
标签: python pandas indexing dataframe hdf5