简体   繁体   English

如何使用循环保存 excel 页面文件?

[英]How to Save excel pages file with a loop?

i would like to save a different dataframe in different excel pages withb a simpler loop.我想用更简单的循环在不同的 excel 页面中保存不同的 dataframe。 How can i construct correctly this loop?我怎样才能正确地构造这个循环?

my Currently codes are:我目前的代码是:

for fund in list(read_ex.keys()):
    writer = pd.ExcelWriter(excel_file, engine='xlsxwriter')
    data_2             .to_excel(writer, sheet_name= 'Df_ag')
    read_ex[fund]      .to_excel(writer, sheet_name= fund[:28])
    writer.save()

but the returns are only two page: the data_2 and the last in the loop.但返回只有两页:data_2 和循环中的最后一页。 Thank you for your time感谢您的时间

Imopla伊莫普拉

For future readers:对于未来的读者:

I have been resolved this quastion in this way:我已经以这种方式解决了这个问题:

writer = pd.ExcelWriter(excel_file, engine='xlsxwriter')
data_2             .to_excel(writer, sheet_name= 'Df_ag')

for fund in list(read_ex.keys()):
    read_ex[fund]      .to_excel(writer, sheet_name= fund[:28]) 
 
writer.save()  

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM