Saving a Pandas Dataframe as a CSV

Last Updated : 13 Jan, 2026

Saving a Pandas DataFrame as a CSV allows us to export processed data into a structured file format for storage and sharing. It helps preserve analysis results so the data can be reused across different tools and workflows. Here, we are taking sample data to convert DataFrame to CSV.

Python
import pandas as pd
nme = ["Aparna", "Pankaj", "Sudhir", "Geeku"]
deg = ["MBA", "BCA", "M.Tech", "MBA"]
scr = [90, 40, 80, 98]
data = {'Name': nme, 'Degree': deg, 'Score': scr}
df = pd.DataFrame(data)

df

Output:

Screenshot-2026-01-12-110940
Output

Export CSV to a Working Directory

Here, we simply export a Dataframe to a CSV file using df.to_csv().

Python
df.to_csv('file1.csv')

Saving CSV Without Headers and Index

Here, we are saving the file with no header and no index number.

Python
df.to_csv("file2.csv", header=False, index=False)

df = pd.read_csv("file2.csv", header=None)
df

Output:

Screenshot-2026-01-12-111106
Output

Write a DataFrame to CSV file using Tab Separator

We can also save our file with some specific separate as we want. i.e "\t" .

Python
import pandas as pd
users = {
    "Name": ["Amit", "Cody", "Drew"],
    "Age": [20, 21, 25]
}
df = pd.DataFrame(users)
df.to_csv("Users.csv", sep="\t", index=False)
new_df = pd.read_csv("Users.csv", sep="\t")
new_df

Output:

Screenshot-2026-01-12-110929
Output
Comment

Explore