简体   繁体   English

如何将df保存到多个位置的两个Excel文件中?

[英]How to save a df into two excel files in multiple locations?

Im trying to save the excel file generated in two different folders (output1, output2) 我试图保存在两个不同的文件夹(output1,output2)中生成的excel文件

I tried this and didnt worked 我尝试了这个,没有工作

writer = pd.ExcelWriter([output1,output2], engine='xlsxwriter')
df1.to_excel(writer, sheet_name='sheeta', index = None)

Thanks 谢谢

You can copy the file using How do I copy a file in Python? 您可以使用如何在Python中复制文件来复制文件? after you created it once ... or simply write it twice: 创建一次之后 ...或只需编写两次即可:

import pandas as pd

output1 = "p.xlsx"
output2 = "q.xlsx"
df = pd.DataFrame({'Data': [10, 20, 30, 20, 15, 30, 45]})

for o in [output1,output2]:
    writer = pd.ExcelWriter(o, engine='xlsxwriter')
    df.to_excel(writer, sheet_name='Sheet1')
    writer.save()

Results in 2 files being written, containing the data: 结果将写入2个文件,其中包含数据:

xlxs内容

Doku: Doku:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在python 2.7中通过pickle存储多个文件(两个列表和一个df) - How to store multiple files (two list and a df) by pickle in python 2.7 计算 2 个不同文件中多个点之间两个位置的距离 - Calculate Distance for two locations between multiple points in 2 different files 如何将pandas df保存到excel表格然后格式化? - How do I save a pandas df to excel sheet then format it? 如何在 AWS Glue 中将多个 Excel 文件编译并保存在一个 Excel 文件中 - How to compile and save multiple Excel files in one Excel file in AWS Glue 如何使用 Pandas 更新多个 excel 文件并保存更新后的文件而不合并它们 - How to use Pandas to update multiple excel files and save the updated files without combinig them 如何使用 Pandas 删除多个 excel 文件的列值并保存每个文件而不合并它们 - How to use Pandas to delete column values for multiple excel files and save each of the files without combining them 在多个位置整理代码文件 - Collating code files in multiple locations OpenPyxl 将 python df 保存到具有多张纸的 excel 文件中,但是当我打开文件时,它会在第一张纸上打开 - OpenPyxl save python df into excel file with multiple sheets but when I open the file it opens on the first sheet 将pandas df写入Excel,并将其保存到副本中 - Write a pandas df into Excel and save it into a copy 如何在 Python 中保存多个文件? - How to save multiple files in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM