用户ID之后的excel表使用for for循环
给定上述数据,我想能够姓名每个Excel表由ID。但是代码仅在上一个ID之后名称表。
这是我的代码:
import pandas as pd
import xlsxwriter
df_dummy = pd.read_csv('dummy.csv')
id_store = df_dummy['id'].unique()
for i in id_store:
print (i)
workbook_dummy = xlsxwriter.Workbook('store_dummy.xlsx')
worksheet = workbook_dummy.add_worksheet('store {}'.format(i))
workbook_dummy.close()
Given the data above, I want to be able to name each excel sheet by the id. But the code only names sheet after last id.
Here is my code:
import pandas as pd
import xlsxwriter
df_dummy = pd.read_csv('dummy.csv')
id_store = df_dummy['id'].unique()
for i in id_store:
print (i)
workbook_dummy = xlsxwriter.Workbook('store_dummy.xlsx')
worksheet = workbook_dummy.add_worksheet('store {}'.format(i))
workbook_dummy.close()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在for循环之前,请尝试创建XLSXWriter Workbook对象。
Try creating the XlsxWriter Workbook object before the for loop.