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.
CodePudding user response:
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
CodePudding user response:
writer = pd.ExcelWriter(file_path, engine = 'openpyxl', mode = 'a')
df1.to_excel(writer, sheet_name = 'test1', index = False)
writer.save()
Just gotta append