Categories
Python Answers

How to write a Python Pandas DataFrame to CSV file?

Spread the love

To write a Python Pandas DataFrame to CSV file, we call the to_csv method on the data frame.

For instance, we write

df.to_csv(file_name, encoding='utf-8', index=False)

to call to_csv on the df data frame.

file_name is the path of the output file.

encoding sets the CSV encoding.

We hide the row index by setting index to false.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *