python - 如何将多个 pandas 数据帧写入单个输出 excel 文件?

标签 python python-3.x pandas dataframe

<分区>

我目前正在研究 Python3,并且有大量相关的 pandas dataframes。我需要将它写入单个 excel 文件,每个数据框作为一个单独的选项卡,我可以将它们分别写入 excel 文件,然后复制、粘贴到一个文件中。但是,我正在寻找更自动化的问题解决方案。 预先感谢您的帮助。

最佳答案

这是为你做的代码:

fname = 'foobar.xlsx'
writer = pd.ExcelWriter(fname)
df1.to_excel(writer, "sheet1", index=False)
df2.to_excel(writer, "sheet2", index=False)
## more dataframes goes here
writer.save()

关于python - 如何将多个 pandas 数据帧写入单个输出 excel 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42562609/

相关文章:

python-3.x - pandas groupby apply 不会广播到 DataFrame

python - 如何仅聚合混合 dtypes 数据框中的数字列

python - 需要使用python清理网络抓取的数据

python - 如何绘制二维直方图?

python - 从多个集合中累积加权计数的最快方法。计数器对象?

python - Postgres `WITH ins AS ...` 将所有内容都转换为文本

python-3.x - 如何使用 VIPS 进行图像归一化?

python-3.x - 导入错误 : No module named 'numpy' in Windows

python - 从 Excel 表构建 HDF5 结构

regex - 替换 Pandas 出生日期的前几位