October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Pandas DataFrame to CSV: to_csv() Without Index, Append, and More

Use pandas to_csv(index=False) to omit row labels. For appending, combine mode="a" with header=False when the existing CSV already has column names.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To save a pandas DataFrame as a CSV without adding its row index, use df.to_csv("output.csv", index=False). To append rows to a CSV that already has a header, use df.to_csv("output.csv", mode="a", header=False, index=False)—and make sure the new DataFrame’s columns are in the same order as the existing file.

Save a DataFrame to CSV without the index

to_csv() writes the DataFrame’s row index by default. Set index=False to omit it while keeping the column names in the first row:

As an Amazon Associate I earn from qualifying purchases.

df.to_csv("output.csv", index=False)

This is usually the right choice when the receiving application expects only the data columns. The index and header are separate: index=False removes row labels, while header=False removes column names. If the recipient requires a headerless file, use both options:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
df.to_csv("output.csv", index=False, header=False)

That output has no column-name row, so use header=False only when the consumer expects that format. The pandas DataFrame.to_csv API documentation describes these defaults and options.

Append rows without writing the header again

Use mode="a" to append to a file rather than replace its contents. If the file already contains the column-name row, also set header=False so the new write does not add another header:

df.to_csv("output.csv", mode="a", header=False, index=False)

This assumes the existing file’s header and the DataFrame columns match, including their order. Append mode adds bytes to the end of the destination; it does not check that the incoming columns fit the existing schema. If the destination does not yet exist, create it with a header first, then append subsequent batches without one.

The default write mode, "w", truncates an existing destination before writing. Use mode="x" when you want exclusive creation that fails if the destination already exists. These modes control the destination; they do not control whether an index or header is included.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Return CSV text or write to a file object

Pass a path to write a file. If you omit the destination, to_csv() returns CSV text instead:

csv_text = df.to_csv(index=False)

You can also pass a writable file-like object. For a text file object, pandas recommends opening it with newline="":

with open("output.csv", "w", newline="", encoding="utf-8") as file:
    df.to_csv(file, index=False)

Set CSV formatting for the receiving application

The comma delimiter and UTF-8 encoding are defaults, but a downstream system may require different conventions. For example, this writes missing values as NA, floats to two decimal places, and dates as year-month-day:

df.to_csv(
    "output.csv",
    index=False,
    na_rep="NA",
    float_format="%.2f",
    date_format="%Y-%m-%d",
    encoding="utf-8",
)

Choose these values to match the consumer rather than treating them as universal settings. Consider the following options when defining the output:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • sep changes the delimiter, such as to a tab for tab-separated output.
  • na_rep sets the text used for missing values.
  • float_format and date_format control how numeric and date values are represented.
  • CSV quoting and escaping options matter when fields contain delimiters, quotation marks, or line breaks.
  • chunksize sets the number of rows written at a time; the API does not promise a particular speed or memory improvement for a workload.

For compressed output, compression="infer" lets pandas infer a supported method from a path suffix such as .gz, .bz2, .zip, .xz, or .zst. You can also specify a compression method explicitly. Confirm that the receiving application can read the chosen compressed format.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Read the CSV back with the right options

Writing without an index is only one part of a clean round trip. When reading the file into pandas, read_csv has its own settings for interpreting headers and index columns. For a typical file written with index=False and the default header, pandas can infer the column names from the first row:

restored = pd.read_csv("output.csv")

If the CSV has no header row, specify that when reading it; if a file contains a column intended to become the index, configure index_col accordingly. Parsing does not guarantee that every value’s inferred type will be identical to the original DataFrame. See the read_csv API documentation for the reader’s options.

When CSV is not the right output format

CSV is plain delimited text and works well when the next tool expects that format. If the consumer supports a binary columnar format, pandas also provides DataFrame.to_parquet; using it requires either pyarrow or fastparquet. CSV and Parquet serve different compatibility and representation needs, and the cited pandas documentation does not establish a universal speed or file-size winner. See the to_parquet API documentation.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check documentation against your pandas version

Function signatures and supported details can change between pandas releases. The to_csv API page cited here is development documentation, while the linked reader and Parquet API pages describe pandas 3.0.6. Consult the documentation for your installed pandas version if a particular option is unavailable or behaves differently.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.