如何将 pandas 数据添加到现有的 csv 文件? [英] How to add pandas data to an existing csv file?
本文介绍了如何将 pandas 数据添加到现有的 csv 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以使用 pandas to_csv()
函数将数据帧添加到现有的 csv 文件中.csv 文件与加载的数据具有相同的结构.
I want to know if it is possible to use the pandas to_csv()
function to add a dataframe to an existing csv file. The csv file has the same structure as the loaded data.
推荐答案
可以在pandas中指定python写模式to_csv
函数.对于附加,它是a".
You can specify a python write mode in the pandas to_csv
function. For append it is 'a'.
就你而言:
df.to_csv('my_csv.csv', mode='a', header=False)
默认模式是w".
这篇关于如何将 pandas 数据添加到现有的 csv 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文