Storing Pandas objects along with regular Python objects in HDF5

后端 未结 1 1747
猫巷女王i
猫巷女王i 2021-02-19 03:41

Pandas has a nice interface that facilitates storing things like Dataframes and Series in an HDF5:

random_matrix  = np.random.random_integers(0,10, m_size)
my_da         


        
1条回答
  •  情深已故
    2021-02-19 04:05

    Here's the example from the cookbook: http://pandas.pydata.org/pandas-docs/stable/cookbook.html#hdfstore

    You can store arbitrary objects as the attributes of a node. I belive there is a 64kb limit (I think its total attribute data for that node). The objects are pickled

    In [1]: df = DataFrame(np.random.randn(8,3))
    
    In [2]: store = HDFStore('test.h5')
    
    In [3]: store['df'] = df
    
    # you can store an arbitrary python object via pickle
    In [4]: store.get_storer('df').attrs.my_attribute = dict(A = 10)
    
    In [5]: store.get_storer('df').attrs.my_attribute
    {'A': 10}
    

    0 讨论(0)
提交回复
热议问题