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.