I have a template file in Excel format. This template contains a title, subtitle and 2 headers that are located in A5:B5. How can I append my pandas DataFrame df
to this template without deleting titles and headers? In particular, I want pandas DataFrame to be inserted starting from A6:B6, and then I want to save the result as a new file result.xlsx
.
This is what I have so far.
import pandas as pd
from openpyxl import load_workbook
df = pd.DataFrame({'a':[1,3,5,7,4,5,6,4,7,8,9],
'b':[3,5,6,2,4,6,7,8,7,8,9]})
book = load_workbook("C:/template.xlsx")
writer = pd.ExcelWriter('template.xlsx')
df.to_excel(writer,'Sheet1',index=False)
writer.save()