chyuyuzz 2018-02-06 11:12 采纳率: 50%
浏览 6642
已采纳

python pandas to_excel为什么会自动删除其他sheet

df = pandas.read_excel('test.xlsx')
df = pandas.pivot_table(df, index=['a'], columns=['b'], aggfunc=numpy.sum)
excelWriter=pandas.ExcelWriter('test_new.xlsx')--test_new.xlsx是一个已经存在的excel文件,有两个sheet1、sheet2
df.to_excel(excelWriter, sheet_name='Sheet1')
excelWriter.save()
执行完之后,之前test_new.xlsx里的Sheet2为什么没有了,怎么才能保留

  • 写回答

5条回答 默认 最新

  • shihuibei 2018-02-06 15:55
    关注

    我搜索了一波,无法实现
    https://github.com/pandas-dev/pandas/issues/3441
    之前有人在github上面建议,希望增加一个选项,但是被开发者认为不可实现,所以关闭了issue

    你可以使用

    openpyxl 引擎试试。
    https://stackoverflow.com/a/20221655/4795055

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?