Skip to the converter
Pandas to CSV

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

Upload a file, paste your data, or use Pandas code.

Your data stays in your browser. Nothing is uploaded.

CSV options

Every control maps to a real to_csv() parameter, and defaults match pandas.
Basic options
Name for the downloaded file and written in the generated code.
Keep the first row as column names (header=True).
Include the DataFrame index as the first column.
Commas are the usual choice for CSV files.
UTF-8 is standard. No encoding= argument needed.
More options— formatting, columns, quoting, line endings
Formatting
Choose how decimal numbers should be written. Integer columns are left as integers.
Choose how missing values should appear in the CSV.
Applies strftime format to date columns.
Columns

Add some data and detected columns will be listed here.

Advanced CSV settings
Controls which fields are wrapped in quotes.
Character used to quote a field. Default is a double quote.
Needed when quoting is disabled and a value contains the separator.
End-of-line character at the end of each row.
Header name for the row numbers column when enabled.
Append adds rows to an existing file instead of replacing it.
Character used for decimal points (use "," for European formats).

Your CSV

Add your data to get started. Upload a file, paste your data, or use Pandas code.

No CSV yet. Upload a CSV or Excel file, paste tabular rows, or use Pandas code to preview and download your CSV.

Pandas code

The 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)
A DataFrame written to output.csv in the current directory.

That call produces exactly this file:

Name,Age,City,Score
Alice,25,Delhi,91.5
Bob,30,Mumbai,87.25
Charlie,28,Chandigarh,94.75
Four columns, three data rows, no index column, comma separated.

In the converter above, the same result takes four steps, and every one of them is optional except the first.

  1. 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.
  2. Set the options that matter. index=False is 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.
  3. 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.
  4. Download the CSV, or copy the code. The download is a real file assembled in the browser. The snippet is thedf.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.

Pandas DataFrame.to_csv() arguments, what each one does, and an example value
ArgumentWhat it changesExample
path_or_bufWhere the file is written. Omit it and the CSV comes back as a string."output.csv"
sepThe field delimiter.sep=";"
headerWrite the column names as the first row, or leave them out.header=False
indexWrite the row index as the first column.index=False
index_labelColumn name for that index column.index_label="row_id"
na_repText used for NaN and other missing values.na_rep="NULL"
float_formatprintf-style pattern applied to float columns only.float_format="%.2f"
date_formatstrftime pattern applied to datetime columns.date_format="%Y-%m-%d"
columnsThe subset of columns to write, in the order given.columns=["Name", "Score"]
mode"w" overwrites the file, "a" appends to it.mode="a"
encodingText encoding of the written file.encoding="utf-8-sig"
quotingcsv module quoting style: 0 minimal, 1 all, 2 non-numeric, 3 none.quoting=csv.QUOTE_ALL
quotecharThe character used to quote a field.quotechar="'"
escapecharEscapes the delimiter when quoting is turned off.escapechar="\\"
lineterminatorRow separator. Defaults to the operating system line ending.lineterminator="\r\n"
decimalCharacter 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)
Common for locales where the comma is the decimal separator.

Append rows to a file that already exists

df.to_csv("output.csv", mode="a", header=False, index=False)
Without header=False, the column names are written again in the middle of the file.

Write floats rounded to two decimal places

df.to_csv("output.csv", index=False, float_format="%.2f")
Formatting only — the DataFrame keeps its full precision.

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")
The BOM tells Excel the file is UTF-8; CRLF matches Windows line endings.

Get the CSV as a string

csv_text = df.to_csv(index=False)
print(csv_text.splitlines()[0])  # Name,Age,City,Score
No path means no file: the method returns the text instead.

Write dates in a chosen format

df.to_csv("output.csv", index=False, date_format="%Y-%m-%d")
Applies to datetime columns; the pattern is strftime.

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 → DataFrame
A round trip. One caveat: index=False means the index is not in the file, so read_csv() gives you a fresh RangeIndex rather than the original one.

This 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 pass header=False.
  • Expecting float_format to 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_rep as a real missing-value marker. The file just says NULL. On the way back in,read_csv(..., na_values=["NULL"]) is what turns it into NaN again.
  • 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.

Back to the converter