Say I have two dataframes,
import pandas as pd
df1 = pd.DataFrame({'col1':[0,2,3,2],'col2':[1,0,0,1]})
df2 = pd.DataFrame({'col12':[0,1,2,1],'col22':[1,1,1,1]})
Now df1.to_hdf('nameoffile.h5', 'key_to_store','w',table=True)
successully stores df1
but I want to also store df2
to the same file, but If I try the same method then df1
will just be over written. When I try to load it and I check the keys I only see the info of df2
. How can I store both df1
and df2
in the same h5 file as a table ?
You are using 'w'
which overwrites, by default the mode is 'a'
so you can just do:
df2.to_hdf('nameoffile.h5', 'key_to_store', table=True, mode='a')
Check the docs: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_hdf.html#pandas.DataFrame.to_hdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With