How to take a pandas dataframe and overwrite a spe

2019-07-22 15:27发布

I want to take a dataframe and have it replace the existing data in a specific sheet let's say sheet1. Then I want to take another dataframe and have it append to the data on another sheet lets say sheet2 in the same workbook.

Currently, I have to write in the data into a new excel workbook. I have not been able to find online how to actually replace a sheet within a saved workbook on my machine and/or append another sheet. I can do one after the other if needed.

writer = pd.ExcelWriter('test.xlsx', engine='xlsxwriter') # this output is where my df goes
df.to_excel(writer, sheet_name='Sheet1') # the data goes on this sheet
writer.save()

So the result would be the original workbook, with the same sheets , but with completely new data on the sheets I specified or appended data.

0条回答
登录 后发表回答