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:
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.
#1 Best Overall
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.
Rank #2
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.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteReturn 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:
sepchanges the delimiter, such as to a tab for tab-separated output.na_repsets the text used for missing values.float_formatanddate_formatcontrol how numeric and date values are represented.- CSV quoting and escaping options matter when fields contain delimiters, quotation marks, or line breaks.
chunksizesets 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.
Best Value
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.
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.
Quick Recap
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.




