Pandas Excel Writer using Openpyxl with existing workbook
I have code from a while ago that I am re-using for a new task. The task is to write a new DataFrame into a new sheet, into an existing excel file. But there is one part of the code that I do not understand, but it just makes the code "work". working: from openpyxl import load_workbook import pandas as pd file = r'YOUR_PATH_TO_EXCEL_HERE' df1 = pd.DataFrame({'Data': [10, 20, 30, 20, 15, 30, 45]}) book = load_workbook(file) writer = pd.ExcelWriter(file, engine='openpyxl') writer.book = book # <---------------------------- piece i do not understand df1.to_excel(writer, sheet_name='New', index