【发布时间】:2015-12-20 19:13:51
【问题描述】:
我有一个包含 pandas Series/DataFrame 表的 HDF5 文件。我需要获取存储在 HDF 中的键下的表的(熊猫)索引,但不一定是整个表:
我可以想到两种(实际上相同)获取索引的方法:
import pandas as pd
hdfPath = 'c:/example.h5'
hdfKey = 'dfkey'
# way 1:
with pd.HDFStore(hdfPath) as hdf:
index = hdf[hdfKey].index
# way 2:
index = pd.read_hdf(hdfPath, hdfKey)
但是对于大约 2000 行的 pandas Series,这需要 0.6 秒:
%timeit pd.read_hdf(hdfPath, hdfKey).index
1 loops, best of 3: 605 ms per loop
有没有办法只获取 HDF 中表的索引?
【问题讨论】:
标签: python hdf5 pytables h5py hdf