While trying to read a h5 file I get the following error:
ValueError: key must be provided when HDF5 file contains multiple datasets
.
f=pd.read_hdf('file_path')
ValueError Traceback (most recent call last)
384 for group_to_check in groups[1:]:
385 if not _is_metadata_of(group_to_check, candidate_only_group):
--> 386 raise ValueError('key must be provided when HDF5 file '
387 'contains multiple datasets.')
388 key = candidate_only_group._v_pathname
ValueError: key must be provided when HDF5 file contains multiple datasets.
Can anyone send me the complete code so that I can resolve this error and work in pandas
?
As @AT_asks mentioned in a comment, you have to provide the name of the group that you want to open in the H5 file. If you do not know what the name could be, you can have look at which groups the file contains:
with pd.HDFStore('file_path') as hdf:
# This prints a list of all group names:
print(hdf.keys())
Pick one group name, and open it by using the key
parameter of read_hdf
:
f = pd.read_hdf('file_path', key='your_group')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With