Pandas How To Uncategorized How to write to csv in Pandas

How to write to csv in Pandas

To write a Pandas DataFrame to a CSV file, you can use the to_csv method. Here’s a simple example:

import pandas as pd

# Create a DataFrame
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})

# Write the DataFrame to a CSV file
df.to_csv('example.csv', index=False)

In this example, we create a DataFrame and then write it to a CSV file named example.csv using the to_csv method. The index parameter is set to False to exclude the index column from the output file.


Leave a Reply

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

Related Post