pandas HDFStore - how to reopen?

前端 未结 3 1034
天命终不由人
天命终不由人 2021-02-12 11:22

I created a file by using:

store = pd.HDFStore(\'/home/.../data.h5\')

and stored some tables using:

store[\'firstSet\'] = df1
s         


        
相关标签:
3条回答
  • 2021-02-12 11:51

    I had the same problem and finally fixed it by installing the pytables module (next to the pandas modules which I was using):

    conda install pytables

    which got me numexpr-2.4.3 and pytables-3.2.0

    After that it worked. I am using pandas 0.16.2 under python 2.7.9

    0 讨论(0)
  • 2021-02-12 11:55

    You could try doing instead:

    store = pd.io.pytables.HDFStore('/home/.../data.h5')
    df1 = store['firstSet']
    

    or use the read method directly:

    df1 = pd.read_hdf('/home/.../data.h5', 'firstSet')
    

    Either way, you should have pandas 0.12.0 or higher...

    0 讨论(0)
  • 2021-02-12 11:56

    In my hands, following approach works best:

    df = pd.DataFrame(...)
    
    "write"
    with pd.HDFStore('test.h5',  mode='w') as store:
        store.append('df', df, data_columns= df.columns, format='table')
    
    "read"
    with pd.HDFStore('test.h5',  mode='r') as newstore:
        df_restored = newstore.select('df')
    
    0 讨论(0)
提交回复
热议问题