I want to fill in some pandas data frames into an existing excel file. I followed the instructions in: How to write to an existing excel file without overwriting data (using pandas)? using:
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()
However, the existing sheets will be deleted, the "example" sheet is generated and only the df is integrated at the defined location. What did I do wrong? I want the "data_df" written into the existing excel file in the existing "example" sheet, keeping the other sheets and data.
Thanks
Example df:
data_df=pd.DataFrame(np.arange(12).reshape((2, 6)), index=["Time","Value"])