Writing a pandas DataFrame to CSV file

import pandas as pd

# create a sample 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('sample.csv', index=False)

Watch a course Python - The Practical Guide

In the above code snippet, the to_csv method is used to write a DataFrame to a CSV file. The first argument to the method is the file path where the CSV file will be saved. The index=False argument is used to prevent the DataFrame's index from being written to the file.