I need to write multiple dataframes to an excel file. These dataframes needs to be written to a specific sheet and it should not overwrite existing data on that sheet.
The code I have is as follows:
excelbook = test.xlsx
book = load_workbook(excelbook)
writer = pd.ExcelWriter(excelbook, engine = 'openpyxl')
writer.book = book
df.to_excel(writer, sheet_name = 'apple', startcol=5, startrow=0)
writer.save()
writer.close()
Problem with my code is, each time I run it to write a dataframe, it is creating a new sheet in the excel file. For example, if the sheet name I need is "apple", then since I'm running this piece of code 3 times (to write 3 dataframes to the same sheet), it is creating a new sheet each time and naming them as - "apple1", "apple2" and "apple3"
I need to write multiple dataframes to the same excel file, to the same sheet in that file, without overwriting the existing data in the sheet.
Please help. Thanks in advance.