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为什么没有了,怎么才能保留
python pandas to_excel为什么会自动删除其他sheet
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
5条回答 默认 最新
- shihuibei 2018-02-06 15:55关注
我搜索了一波,无法实现
https://github.com/pandas-dev/pandas/issues/3441
之前有人在github上面建议,希望增加一个选项,但是被开发者认为不可实现,所以关闭了issue你可以使用
openpyxl 引擎试试。
https://stackoverflow.com/a/20221655/4795055本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报