0

I am trying to write my dataframe to excel. I am able to write the data using pandas.

df.to_excel(r'Path where the exported excel file will be stored\File Name.xlsx', index = False)

But the excel I am trying to write contain some template which look something like this. enter image description here

Whenever I try to write the df values to excel using df.to_excel it always remove the template and write is there way I can write the data below the template in excel.

Any suggestions?

2

1 Answer 1

1

I am able to solve this using below code:

import pandas as pd
from openpyxl import load_workbook

path = "Excel.xlsx"
book = load_workbook(path)
writer = pd.ExcelWriter("Excel.xlsx", engine='openpyxl')
writer.book = book
writer.sheets = {ws.title: ws for ws in book.worksheets}
df.to_excel(writer, startrow=writer.sheets['Sheet1'].max_row, index=False, header=False)
writer.save()
Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.