Skip to content
Advertisement

save data to new worksheet, in existing workbook using python

created a new dataframe named df3 and saved to excel workbook named masterdata.xlsx, later created another dataframe named table when I try to write that dataframe to sheet2 of masterdata.xlsx, it overrighted the first created dataframe.

masterdata.xlsx have two sheets, sheet1 and sheet2. sheet1 have some data. how to save newly created dataframe table to sheet2 without losing sheet1 using python.

Advertisement

Answer

You need to create pandas excel writer and then save on different sheets like this:

df1.to_excel(writer, sheet_name='Sheet1')
df2.to_excel(writer, sheet_name='Sheet2')
Advertisement