Search code examples
pythonpandashdf5stathdf

wanna to read hdf file in dataframe


gss = pd.read_hdf('gss.hdf5', 'gs') this the code i have used on VS code. and i got this

Traceback (most recent call last):
  File "d:\pthon_txt\t.py", line 4, in <module>
    gss = pd.read_hdf('gss.hdf5', 'gs')
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mohammed\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\io\pytables.py", line 442, in read_hdf
    return store.select(
           ^^^^^^^^^^^^^
  File "C:\Users\Mohammed\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\io\pytables.py", line 847, in select
    raise KeyError(f"No object named {key} in the file")
KeyError: 'No object named gs in the file'
PS D:\pthon_txt> 

i wanna to load this hdf file in pandas data frame


Solution

  • The error is saying that the key gs doesn't exist in the file. If there's only one key you can use read_hdf without the key parameter, eg :

    df = pd.read_hdf('gss.hdf5')