How to add pandas data to an existing csv file?

Ayoub Ennassiri picture Ayoub Ennassiri · Jul 8, 2013 · Viewed 305.4k times · Source

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.

Answer

tlingf picture tlingf · Jul 31, 2013

You can specify a python write mode in the pandas to_csv function. For append it is 'a'.

In your case:

df.to_csv('my_csv.csv', mode='a', header=False)

The default mode is 'w'.