How to write a Pandas Dataframe into a HDF5 dataset

后端 未结 2 527
既然无缘
既然无缘 2021-01-12 11:59

I\'m trying to write data from a Pandas dataframe into a nested hdf5 file, with multiple groups and datasets within each group. I\'d like to keep it as a single file which w

2条回答
  •  悲哀的现实
    2021-01-12 12:21

    df.to_hdf() expects a string as a key parameter (second parameter):

    key : string

    identifier for the group in the store

    so try this:

    df.to_hdf('database.h5', ds.name, table=True, mode='a')
    

    where ds.name should return you a string (key name):

    In [26]: ds.name
    Out[26]: '/A1'
    

提交回复
热议问题