This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy | |
df1 = pd.DataFrame(np.random.rand(100,5), columns=list('abcde')) # example data table with 5 columns | |
df2 = pd.DataFrame(np.random.rand(100,5), columns=list('abcde')) # example data table with 5 columns | |
filename = "data.hdf5" | |
df1.to_hdf(filename,"X", mode="w") # "X" is the key to access df1. mode="w" creates a new file. | |
df2.to_hdf(filename,"Y",format="table",data_columns=True, mode="a", index=False) | |
# table format allows to access by columns. mode="a" is to append. | |
data1 = pd.read_hdf(filename,"X") | |
data2 = pd.read_hdf(filename,"Y",columns=["a","c"]) # reading the table df2 of columns a and c |