import pandas as pd
with pd.ExcelWriter('a.xls') as writer:
    df1.to_excel(writer, 'sheet1')
    df2.to_excel(writer, 'sheet2')
结果:新生成的结果sheet1和sheet2生成后,会将原有的excel表格中的数据全部覆盖
所以,在已有的excel文件上操作的方法如下
from openpyxl import load_workbook
book = load_workbook('a.xlsx')
writer = pd.ExcelWriter('a.xlsx', engine='openpyxl')
writer.book = book
df1.to_excel(writer, 'sheet1')
df2.to_excel(writer, 'sheet2')
writer.save()
1、openpyxl为第三方包,安装方法:
pip3 install openpyxl
df1 = pd.DataFrame({"需求名称": prd_name, "需求bug总数": prd_bugnum, "Android BUG数": prd_bugnum_android,
                    "iOS BUG数": prd_bugnum_ios, "server BUG数": prd_bugnum_server, "FE BUG数": prd_bugnum_fe,
                    "需求变更个数": prd_bugnum_pm, "设计缺陷个数": prd_bugnum_design