简体   繁体   English

将DataFrame保存到现有Excel工作表的下一行

[英]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". 我需要做的最后一件事是将内容从“ dff”保存到现有excel工作表“ 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. 问题出在最后第二行,即“ startrow =”部分。 So far I can make it enter the dataframe content to row 3, but it overwrites the contents. 到目前为止,我可以使它将数据帧内容输入到第3行,但是它将覆盖内容。

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? 说我有内容08 / 09-2019 00,00,00,00如何将其添加到Excel工作表的下一个空行中?

尝试这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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