【发布时间】:2018-01-19 22:11:20
【问题描述】:
我是 Python 新手。我正在开发一个大型分析程序,这是它的一个 sn-p。现在,这个 sn-p 导出多个 excel 文件。是否可以将每个循环所做的事情保存在单个 Excel 文档中的工作表上?所以基本上现在,它导出 5 个文件,而不是导出 5 个单独的文件,我可以使用这个循环并导出 1 个文件,它有 5 张纸吗?
x = 0
y = 0
#these are empty variables for the while loop
#while loop that loops up to the system amount
#breaks up df into systems
#exports excel for each system
while x < int(SystemCount):
x += 1
y += 1
System = minus4[minus4['System'] == "System " + str(y)]
System.to_excel('U4Sys' + str(y) + '.xlsx', sheet_name='sheet1', index=False)
print(System.head())
最后的打印打印这个
email System
test1@test.com System 1
test2@test.com System 1
test3@test.com System 1
test4@test.com System 1
test5@test.com System 1
email System
test1@test.com System 2
test2@test.com System 2
test3@test.com System 2
test4@test.com System 2
test5@test.com System 2
email System
test1@test.com System 3
test2@test.com System 3
test3@test.com System 3
test4@test.com System 3
test5@test.com System 3
感谢您抽出宝贵时间阅读本文!
【问题讨论】:
-
您使用什么库将其发送到 Excel?
-
你试过 XlsxWriter 吗? xlsxwriter.readthedocs.io
-
嘿抱歉,我正在使用 Pandas、ExcelWriter 和 ExcelFile
标签: python excel pandas while-loop export-to-excel