Reputation: 1025
How to open a HDF5 file with pandas.read_hdf
when the keys are not known?
from pandas.io.pytables import read_hdf
read_hdf(path_or_buf, key)
pandas.__version__ == '0.14.1'
Here the key parameter is not known. Thanks
Upvotes: 4
Views: 2407
Reputation: 2682
Or you could just do store.keys()
https://github.com/pydata/pandas/blob/master/pandas/io/pytables.py#L492
Upvotes: 3
Reputation: 393893
Having never worked with hdf files before I was able to use the online docs to cook an example:
In [59]:
# create a temp df and store it
df_tl = pd.DataFrame(dict(A=list(range(5)), B=list(range(5))))
df_tl.to_hdf('store_tl.h5','table',append=True)
In [60]:
# we can simply read it again and the keys are displayed
store = pd.HDFStore('store_tl.h5')
# keys will be displayed in the output
store
Out[60]:
<class 'pandas.io.pytables.HDFStore'>
File path: store_tl.h5
/table frame_table (typ->appendable,nrows->5,ncols->2,indexers->[index])
In [61]:
# read it back in again
t = pd.read_hdf('store_tl.h5', 'table')
t
Out[61]:
A B
0 0 0
1 1 1
2 2 2
3 3 3
4 4 4
So basically just loading it using HDFStore
and passing the path and then just displaying the object will print the keys in the output.
Upvotes: 4