pandas HDFStore - how to reopen?

前端 未结 3 1038
天命终不由人
天命终不由人 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: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')
    

提交回复
热议问题