Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: key must be provided when HDF5 file contains multiple datasets while reading h5 file in pandas i am getting this error

Tags:

pandas

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?

like image 764
ved Avatar asked May 27 '19 10:05

ved


1 Answers

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')
like image 143
mrzo Avatar answered Nov 17 '22 11:11

mrzo