简体   繁体   中英

Save DataFrame to next row in existing excel sheet

Ideally I'm building a self-updating mechanism. The last thing I need to do is save content from "dff" to the next empty row in an existing excel sheet "test.xlsx".

现有的Excel工作表“ test.xlsx”

book = load_workbook("test.xlsx")
writer = pd.ExcelWriter('test.xlsx', engine='openpyxl') 
writer.book = book
writer.sheets = dict((ws.title, ws) for ws in book.worksheets)
dff.to_excel(writer, startrow=len(dff), header=None)
writer.save()

The issue is around the 2nd last row, the "startrow=" part. So far I can make it enter the dataframe content to row 3, but it overwrites the contents.

Say I have content 08/09-2019 00, 00, 00, 00 How would I add it to the next empty row of my excel sheet?

尝试这个

dff.to_excel(writer, startrow=len(dff)+1, header=False, index=False)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM