问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
import pandas as pd
df=pd.read_excel("xlscl/step1/超市销售数据.xlsx",dtype={"商品编码":str,"商品条码":str})
#代码开始
#代码结束
运行结果及报错内容
import pandas as pd
df=pd.read_excel("xlscl/step1/超市销售数据.xlsx",dtype={"商品编码":str,"商品条码":str})
#代码开始
df1=df["日期"].unique()
for i in df1:
i2=pd.to_datetime(i)
i3=i2.strftime('%Y%m%d')
df2=df.loc[df["日期"]==i,["商品编码","商品名称","合计金额","类别"]]
df6=df2["类别"].unique()
writer=pd.ExcelWriter('xlscl/step3/rq/'+i3+'.xlsx')
k=[]
for n in df6:
df8=df2.loc[df2["类别"]==n]
df8.to_excel(writer,sheet_name=n,index=False)
k.append([n,df8['合计金额'].sum()])
df7=pd.DataFrame(k,columns=["类别","合计金额"])
df7.to_excel(writer,sheet_name="类别统计",index=False,header=["类别","合计金额"])
writer.save()
#代码结束