Skip to content
Advertisement

How to add pandas data to an existing csv file?

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.

Advertisement

Answer

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

In your case:

JavaScript

The default mode is ‘w’.

If the file initially might be missing, you can make sure the header is printed at the first write using this variation:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement