Pandas DataFrame to CSV

  • Post category:Pandas

In this Pandas tutorial, you will learn how to convert Pandas DataFrame to CSV in Python. You can easily save the Pandas DataFrame as CSV file with the following code.

# import Pandas library
import pandas as pd

# create a dataframe
var = pd.DataFrame({'A': [55, 20, 35, 45], 'B': [91, 70, 20, 82], 'C': [90, 30, 50, 78]})

# display the dataframe
print(var)

# save the dataframe to a CSV file
var.to_csv('data.csv')

Output:

    A   B   C
0  55  91  90
1  20  70  30
2  35  20  50
3  45  82  78

Free resources to learn advanced skills: AiHints and CodeAllow