1

I have a dataframe df1 and I want to export it to an Excel which already has some sheets.

I tried using:

writer = pd.ExcelWriter(file_path, engine = 'xlsxwriter')
df1.to_excel(writer, sheet_name = 'test1', index = False)
writer.save() 

This code deletes the existing sheets, and exports df1 into sheet named test1.

1
  • Have you tried loading the existing excel file as a dataframe and then appending the new data to it before finally exporting? Commented Nov 2, 2021 at 8:43

2 Answers 2

1

Check out the documentation https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_excel.html there is an append mode for ExcelWriter

Sign up to request clarification or add additional context in comments.

Comments

1
writer = pd.ExcelWriter(file_path, engine = 'openpyxl', mode = 'a')
df1.to_excel(writer, sheet_name = 'test1', index = False)
writer.save()

Just gotta append

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.