我想只讀取HDF5文件中的特定列並在這些列上傳遞條件。我擔心的是我不想將所有HDF5文件作爲數據幀存儲在內存中。我只想得到我的必要專欄和他們的條件。從hdf5文件讀取特定列並傳遞條件
columns=['col1', 'col2']
condition= "col2==1"
groupname='\path\to\group'
Hdf5File=os.path.join('path\to\hdf5.h5')
with pd.HDFStore(Hdf5File, mode='r', format='table') as store:
if groupname in store:
df=pd.read_hdf(store, key=groupname, columns=columns, where=["col2==1"])
我得到一個錯誤:
TypeError: cannot pass a column specification when reading a Fixed format store. this store must be selected in its entirety
然後我用下面的線僅返回特定的列:
df=store[groupname][columns]
但我不知道我可以通過它的條件。
[Python的熊貓閱讀的可能的複製使用讀\ _hdf和HDFStore.select從HDF5文件的特定值(https://stackoverflow.com/questions/26302480/python-pandas-reading-specific-values-from -hdf5-files-using-read-hdf-and-hdfstor) –