Storing Pandas objects along with regular Python objects in HDF5 -
pandas has nice interface facilitates storing things dataframes , series in hdf5:
random_matrix = np.random.random_integers(0,10, m_size) my_dataframe = pd.dataframe(random_matrix) store = pd.hdfstore('some_file.h5',complevel=9, complib='bzip2') store['my_dataframe'] = my_dataframe store.close()
but if try save other regular python objects in same file, complains:
my_dictionary = dict() my_dictionary['a'] = 2 # <--- error my_dictionary['b'] = [2,3,4] store['my_dictionary'] = my_dictionary store.close()
with
typeerror: cannot create storer for: [_type_map] [group->/par ameters (group) u'',value-><type 'dict'>,table->none,append->false,kwargs- >{}]
how can store regular python data structures in same hdf5 store other pandas objects ?
here's example cookbook: http://pandas.pydata.org/pandas-docs/stable/cookbook.html#hdfstore
you can store arbitrary objects attributes of node. belive there 64kb limit (i think total attribute data node). objects pickled
in [1]: df = dataframe(np.random.randn(8,3)) in [2]: store = hdfstore('test.h5') in [3]: store['df'] = df # can store 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}
Comments
Post a Comment