我想将一些熊猫数据框填入excel文件的现有。我跟着中说明:使用 How to write to an existing excel file without overwriting data (using pandas)? :将pd数据框填入现有excel表格(使用openpyxl v2.3.2)
from openpyxl import load_workbook
import pandas as pd
import numpy as np
book=load_workbook("excel_proc.xlsx")
writer=pd.ExcelWriter("excel_proc.xlsx", engine="openpyxl")
writer.book = book
writer.sheets = dict((ws.title, ws) for ws in book.worksheets)
data_df.to_excel(writer, sheet_name="example", startrow=100, startcol=5, index=False)
writer.save()
然而,现有的片材将被删除,则生成“实例”片并仅在DF所定义的位置被整合。我做错了什么?我希望将“data_df”写入现有“示例”工作表中现有的excel文件中,并保留其他工作表和数据。
感谢
例DF:
data_df=pd.DataFrame(np.arange(12).reshape((2, 6)), index=["Time","Value"])
谢谢!这是非常有用的信息。 – MaxU