'pd.excelwriter not appending to bottom of sheet1. Instead creating new sheets? python
my code isn't working to append new data to the bottom of an existing excel file. It keeps creating new sheets in the file but I need it to append to sheet1 with the new data frame. The headers are all the same.
pip freeze = pandas python: 3.8.10 |openpyxl: 3.0.9 | pandas: 1.1.2 |xlrd 2.0.1
df1= [Order Amount: Item Name: Date:]
[7000 Plastic Cup 7/1/2022]
writer = pd.ExcelWriter('order_history.xlsx', engine='openpyxl')
writer.book = load_workbook('order_history.xlsx')
writer.sheets= dict((ws.title,ws) for ws in writer.book.worksheets)
reader = pd.read_excel('order_history.xlsx',engine='openpyxl')
order_df1.to_excel(writer,index=False,header=False,startrow= len(reader)+1)
writer.close()
This has been a problem I haven't figured out for hours please someone help.
Solution 1:[1]
If you are using pandas 1.4 set the following parameter (see the docs here):
if_sheet_exists='overlay'
Otherwise try with:
startrow = writer.sheets['sheet1'].max_row
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | CAPSLOCK |
