将DataFrame保存到现有Excel工作表的下一行 [英] Save DataFrame to next row in existing excel sheet

查看:686
本文介绍了将DataFrame保存到现有Excel工作表的下一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

理想情况下,我正在建立一种自我更新机制.我需要做的最后一件事是从"dff"中保存内容.到现有excel工作表"test.xlsx"中的下一个空行.

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".

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()

问题出在最后第二行,即"startrow ="部分. 到目前为止,我可以使其输入数据帧内容到第3行,但它将覆盖内容.

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.

说我有内容 08/09-2019 00,00,00,00 如何将其添加到Excel工作表的下一个空白行?

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)

这篇关于将DataFrame保存到现有Excel工作表的下一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆