csv的 pandas 数据帧输出端 [英] pandas DataFrame output end of csv
本文介绍了csv的 pandas 数据帧输出端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何将新的 DataFrame
数据添加到现有 csv 文件的末尾?to_csv
没有提到这样的功能.
I wonder how to add new DataFrame
data onto the end of an existing csv file? The to_csv
doesn't mention such functionality.
推荐答案
您可以使用 to_csv
通过传递一个文件 以追加模式打开:
with open(file_name, 'a') as f:
df.to_csv(f, header=False)
使用header=None
,以免附加列名.
Use header=None
, so as not to append the column names.
事实上,pandas 有一个包装器可以在 to_csv
中使用 mode
参数(参见乔的回答):
In fact, pandas has a wrapper to do this in to_csv
using the mode
argument (see Joe's answer):
df.to_csv(f, mode='a', header=False)
这篇关于csv的 pandas 数据帧输出端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文