pandas 新增sheet,不覆盖原来已经保存的sheet(亲测管用)

#以前的sheet数据很重要,又要新增sheet,很难受,看了一堆帖子没一个回答在点子上,找到了方法,分享给大家

import openpyxl
import pandas as pd
weatherfile = "0317.xlsx"  #路径
writer = pd.ExcelWriter(weatherfile,engine='openpyxl')

pd_data=pd.DataFrame(新数据)   # 

writer = pd.ExcelWriter(weatherfile,engine='openpyxl')
book = openpyxl.load_workbook(writer.path)
writer.book = book
pd_data.to_excel(writer, "新sheet名",index=False)
writer.save()

# 没覆盖,新增成功

 

你可能感兴趣的:(python,pandas,新增sheet不覆盖原数据,数据分析)