Pandas → CSV
Pandas to CSV Converter
Convert your DataFrame to CSV in seconds. Upload a file, paste your data, or use Pandas code.
- Real CSV download
- Copyable
to_csv()code - Browser-only processing
Add your data
Your data stays in your browser. Nothing is uploaded.
CSV options
to_csv() parameter, and defaults match pandas.More options— formatting, columns, quoting, line endings
Your CSV
No CSV yet. Upload a CSV or Excel file, paste tabular rows, or use Pandas code to preview and download your CSV.
Pandas code
df.to_csv() call that reproduces these settings in Python.df.to_csv("output.csv", index=False)Assumes your DataFrame is named df and that pandas is already imported.
This snippet updates live as you paste data and change options.
Your data stays in your browser. Nothing is uploaded to our servers.The parser, the CSV writer and the Python snippet all run as page code in this tab.
How to convert a Pandas DataFrame to CSV
In a script, the whole job is one method call. df.to_csv() takes the output path as its first argument and writes the DataFrame to disk in CSV form; the rest of the arguments decide what the file looks like.
import pandas as pd
df = pd.DataFrame({
"Name": ["Alice", "Bob", "Charlie"],
"Age": [25, 30, 28],
"City": ["Delhi", "Mumbai", "Chandigarh"],
"Score": [91.5, 87.25, 94.75],
})
df.to_csv("output.csv", index=False)That call produces exactly this file:
Name,Age,City,Score
Alice,25,Delhi,91.5
Bob,30,Mumbai,87.25
Charlie,28,Chandigarh,94.75In the converter above, the same result takes four steps, and every one of them is optional except the first.
- Paste your data. Comma, semicolon, tab or pipe separated rows, space-aligned columns as
print(df)shows them, or apd.DataFrame({…})literal copied out of a notebook. - Set the options that matter.
index=Falseis the one most exports need. Header, delimiter, encoding, missing values, float format and date format are all here too, each labelled with the parameter it maps to. - Check the preview. It shows the values as they will be written — same order, same missing-value text, same float formatting — so you can catch a wrong delimiter or an unwanted index column before anything is saved.
- Download the CSV, or copy the code. The download is a real file assembled in the browser. The snippet is the
df.to_csv(...)call that produces the identical file in your own script.
Pandas to_csv() options
Every control in the tool writes exactly one of these arguments, in pandas' own spelling. The examples are literal fragments you can paste into a call.
| Argument | What it changes | Example |
|---|---|---|
| path_or_buf | Where the file is written. Omit it and the CSV comes back as a string. | "output.csv" |
| sep | The field delimiter. | sep=";" |
| header | Write the column names as the first row, or leave them out. | header=False |
| index | Write the row index as the first column. | index=False |
| index_label | Column name for that index column. | index_label="row_id" |
| na_rep | Text used for NaN and other missing values. | na_rep="NULL" |
| float_format | printf-style pattern applied to float columns only. | float_format="%.2f" |
| date_format | strftime pattern applied to datetime columns. | date_format="%Y-%m-%d" |
| columns | The subset of columns to write, in the order given. | columns=["Name", "Score"] |
| mode | "w" overwrites the file, "a" appends to it. | mode="a" |
| encoding | Text encoding of the written file. | encoding="utf-8-sig" |
| quoting | csv module quoting style: 0 minimal, 1 all, 2 non-numeric, 3 none. | quoting=csv.QUOTE_ALL |
| quotechar | The character used to quote a field. | quotechar="'" |
| escapechar | Escapes the delimiter when quoting is turned off. | escapechar="\\" |
| lineterminator | Row separator. Defaults to the operating system line ending. | lineterminator="\r\n" |
| decimal | Character used as the decimal point. | decimal="," |
Source: the pandas DataFrame.to_csv() documentation. The tool on this page supports these arguments and no others.
Common Pandas to CSV examples
These are the exports people reach for most often. Each one is a real call — set the matching options in the tool and it generates the same line.
Save a DataFrame to CSV without the index
df.to_csv("output.csv", index=False)Write a CSV with no header row
df.to_csv("output.csv", header=False, index=False)Write a semicolon-separated file
df.to_csv("output.csv", sep=";", index=False)Append rows to a file that already exists
df.to_csv("output.csv", mode="a", header=False, index=False)Write floats rounded to two decimal places
df.to_csv("output.csv", index=False, float_format="%.2f")Write missing values as NULL
df.to_csv("output.csv", index=False, na_rep="NULL")Export only two columns, in a chosen order
df.to_csv("output.csv", index=False, columns=["Name", "Score"])Write a CSV that Excel reads correctly
df.to_csv("output.csv", index=False, encoding="utf-8-sig", lineterminator="\r\n")Get the CSV as a string
csv_text = df.to_csv(index=False)
print(csv_text.splitlines()[0]) # Name,Age,City,ScoreWrite dates in a chosen format
df.to_csv("output.csv", index=False, date_format="%Y-%m-%d")read_csv() vs to_csv()
The two methods run in opposite directions, and mixing them up is the most common source of confusion. to_csv() writes a DataFrame out to a CSV file;read_csv() reads a CSV file back into a DataFrame.
df.to_csv("output.csv", index=False) # DataFrame → CSV file
back = pd.read_csv("output.csv") # CSV file → DataFrameThis converter only covers the writing direction. For the reading direction, thepandas read_csv() documentation is the reference to use.
Common mistakes when exporting to CSV
- Forgetting
index=False. The index becomes an unnamed first column, and anyone reading the file back gets a column they did not ask for. - Appending with the header still on.
mode="a"writes rows, not structure — so the column names land in the middle of the file unless you also passheader=False. - Expecting
float_formatto round your data. It formats the text that is written. The DataFrame is untouched, and reading the file back gives you the rounded values, not the originals. - Opening a plain UTF-8 file in Excel on Windows. Accented characters show up as mojibake until you write it with
encoding="utf-8-sig". - Treating
na_repas a real missing-value marker. The file just saysNULL. On the way back in,read_csv(..., na_values=["NULL"])is what turns it intoNaNagain. - Writing with a custom separator and reading with the default.
read_csv()assumes a comma unless you tell it otherwise. - Being surprised by the trailing newline. pandas ends the file with a line terminator after the last row, and this converter does the same.
Frequently asked questions
How do I convert a Pandas DataFrame to CSV?
Call df.to_csv("output.csv", index=False). The file path is the first argument, and index=False keeps the row index out of the file. When you leave the path out, the call returns the CSV as a string instead of writing a file.
How do I save a DataFrame to CSV without the index?
Pass index=False. pandas writes the index by default, which adds an unnamed first column when the index is a plain RangeIndex — the single most common surprise when a CSV is opened somewhere else. df.to_csv("output.csv", index=False) is the usual call.
How do I write a CSV without a header row?
Pass header=False: df.to_csv("output.csv", header=False, index=False). pandas writes the column names as a header row by default, so turning it off leaves only the data rows. It is normally combined with index=False, which produces a file of values with no labels at all.
How do I change the delimiter to a semicolon or a tab?
Use the sep argument: sep=";" for semicolons, sep="\t" for tabs and sep="|" for pipes. Whatever you write with, read it back with the same separator — pd.read_csv("output.csv", sep=";").
How do I overwrite an existing CSV file?
mode="w" is the default, so writing to a path that already exists replaces it. Nothing is merged and nothing is prompted for.
How do I append rows to an existing CSV file?
Pass mode="a". On every append after the first, also pass header=False, otherwise the column names are written again in the middle of the file.
How do I write floats with two decimal places?
Use float_format="%.2f" — any printf-style pattern works, such as "%.3f" or "%.4g". It changes the text written, not the data: the DataFrame keeps full precision, and integer columns are unaffected.
How do I export only some columns?
Pass the columns argument to df.to_csv(): df.to_csv("output.csv", columns=["Name", "Score"], index=False). Only those columns reach the file, in the order you list them, and the DataFrame itself is left untouched. The names must match the DataFrame exactly.
How are missing values written to CSV?
As an empty field by default. na_rep="NULL" (or any text) writes that text instead of leaving the field blank. Remember that a reader has to be told about it — pd.read_csv("output.csv", na_values=["NULL"]) — because on the way back in the text is just text.
How do I write a CSV that Excel opens correctly?
Use encoding="utf-8-sig". It writes a UTF-8 byte-order mark, which Excel on Windows needs in order to read accented characters and non-Latin scripts correctly. Add lineterminator="\r\n" if you also want Windows line endings.
How do I get the CSV as a string instead of a file?
Leave the path out: csv_text = df.to_csv(index=False). The return value is the CSV text as a str. Pass a path (or a file object) and the method writes instead and returns None.
Does to_csv() create the file if it does not exist?
Yes. mode="w" creates the file and writes to it. The directory itself must already exist — pandas raises FileNotFoundError if it does not.
What is the difference between read_csv() and to_csv()?
read_csv() reads a CSV file into a DataFrame; to_csv() writes a DataFrame out to CSV. This converter covers the writing direction only.
Is this converter free, and is my data uploaded?
It is free, and nothing is uploaded. The conversion runs in your browser tab: the file is assembled locally and the generated to_csv() call is produced by the same code you can read in the page. No dataset, pasted code or CSV text is ever sent to a server.
Ready to convert your DataFrame?
Your data stays in your browser. Nothing is uploaded to our servers.