gpt4 book ai didi

python - xlsxwriter 覆盖上一张表

转载 作者:太空宇宙 更新时间:2023-11-03 15:56:34 25 4
gpt4 key购买 nike

我正在尝试将数据透视表放在一列上,将详细信息放在第二张纸上。但是详细信息表正在被 xlsxwriter 覆盖。

pivot = pd.pivot_table(df2, index=['Customer_Name'], values=['Billed_Net_Value', 'Sales_Order_Net_Value', 'Open_Amount'], aggfunc=np.sum)
writer = pd.ExcelWriter('SAP.xlsx', engine='xlsxwriter')
pivot.to_excel(writer, sheet_name='Pivot')
writer.save()

filename = 'SAP.xlsx'
workbook = xlsxwriter.Workbook(filename)
worksheet = workbook.add_worksheet('Detail')

最佳答案

我认为您可以通过推迟 .save() 调用来简单地做到这一点:

pivot = pd.pivot_table(df2, index=['Customer_Name'], values=['Billed_Net_Value', 'Sales_Order_Net_Value', 'Open_Amount'], aggfunc=np.sum)
writer = pd.ExcelWriter('SAP.xlsx', engine='xlsxwriter')
pivot.to_excel(writer, sheet_name='Pivot')
df2.to_excel(writer, sheet_name='Detail')
writer.save()

关于python - xlsxwriter 覆盖上一张表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42821139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com