我有大约 200 个 pandas 数据框,每个数据框都有一些独特的列,或者可能完全不同的列。示例:
df1 = pd.DataFrame({
'Product': ['Apple', 'Banana', 'Orange', 'Mango'],
'Quantity': [10, 15, 12, 8],
'Price': [2.5, 1.5, 2, 3],
'Category': ['Fruit', 'Fruit', 'Fruit', 'Fruit']
})
df2 = pd.DataFrame({
'Student Name': ['John', 'Emma', 'Lisa', 'Tom'],
'Age': [18, 17, 19, 18],
'Grade': ['A', 'B', 'A', 'B'],
'City': ['New York', 'London', 'Paris', 'Sydney']
})
df3 = pd.DataFrame({
'Date': ['2021-01-01', '2021-01-02', '2021-01-03', '2021-01-04'],
'Company': ['AAPL', 'GOOG', 'AMZN', 'MSFT'],
'Price': [132.69, 1760.33, 3187.50, 215.41]
})
# and many more
虽然我认为我可以轻松地跳入 Parquet 并创建一个文件夹,但事实证明,如果 Parquet 文件具有不同的架构,则无法以这种方式工作(我还没有实现它,所以也许我错了也是)
显然我已经阅读了这篇文章使用 Parquet 存储多个不同宽度的数据帧?
那么有哪些格式允许在一个文件中存储多个数据帧? 其他 excel
注意:我正在尝试研究
to_orc()
和 orc
格式,但我不知道是否可以合并不同的模式和截止 NA
值。
note2:也许这不是一个可以回答的问题,但您可以帮助分享主题和链接。
您可以使用HDF5。首先使用
pytables
安装
pip install tables
with pd.HDFStore('dataframes.hdf') as hdf:
df1.to_hdf(hdf, key='df1')
df2.to_hdf(hdf, key='df2')
df3.to_hdf(hdf, key='df3')