-1

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

BruceWayne
  • 22,923
  • 15
  • 65
  • 110

2 Answers2

2

To know which keys stored in your HDF store, use the following code:

with pd.HDFStore('gss.hdf5') as store:
    print(store.keys())

After that, you will be able to load your data with the correct key:

gss = pd.read_hdf('gss.hdf5', <KEY>)
Corralien
  • 109,409
  • 8
  • 28
  • 52
0

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') 
Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236