Read CSV with pandas: What read_csv Changes and When to Keep Plain Text

How pandas read_csv turns CSV and TSV text into a DataFrame, where meaning can shift (leading zeros, NA codes, types), and when the raw file is safer.

Searches for a "pd csv reader" are usually about pandas.read_csv, called through the conventional alias pd. It turns delimited text into a DataFrame, a typed in-memory table. This review treats that step as a transformation: what it changes, where meaning can be lost, and when keeping the raw text is the better choice. No benchmarks or test measurements were available for this article, so everything below describes documented default behavior and general, checkable principles rather than measured results.

Short verdict

read_csv suits analysis work such as filtering, aggregating, joining and charting tabular data. Its main benefit is that one call handles delimiters, quoting, headers, missing values and column types. The decisive tradeoff is that it interprets text instead of copying it. Identifiers with leading zeros, codes that look like missing-value markers, very long numeric IDs and dates can all change unless you tell pandas otherwise. Plain text is preferable when you need byte-for-byte fidelity, such as for archiving, audit records, diffing or handing a file to another system unchanged. It is also preferable when the job is only swapping one delimiter for another, or when every column should remain a string.

How read_csv differs from Python's csv module

Python's built-in csv.reader returns each row as a list of strings. It does no type conversion, adds no index and does not reinterpret anything as missing. pandas.read_csv returns a whole table with inferred column types and missing-value handling. Choose the csv module when you want to stream rows and keep the exact strings. Choose read_csv when you want to work with columns.

What read_csv actually changes

The file on disk is never modified. The changes happen in how its contents are interpreted in memory:

  • Delimiters and quoting: the default separator is a comma. Quoted fields keep embedded commas and line breaks together, and the surrounding quote characters are removed from the values.
  • Header: the first row becomes the column names by default. Use header=None if the file has no header row.
  • Encoding: bytes are decoded as UTF-8 unless you pass a different encoding.
  • Types: columns that contain only numbers become integer or float columns. Other columns stay as text.
  • Missing values: empty fields and strings such as "NA", "N/A", "NaN", "null" and "#N/A" become NaN by default.
  • Index: a 0-based integer row index is added. It does not exist in the file.
  • Dates: values stay as text unless you request parsing with parse_dates.

Worked example: where meaning shifts

Consider a small file named customers.csv:

zip,city,amount
02134,Boston,1200
10001,New York,
import pandas as pd

df = pd.read_csv("customers.csv")
print(df)
print(df.dtypes)

With default settings, the output looks like this. In pandas versions that use a dedicated string type by default, the city column shows that type instead of object.

     zip      city  amount
0   2134    Boston  1200.0
1  10001  New York     NaN

zip         int64
city       object
amount    float64
dtype: object

Two changes stand out. First, the ZIP code 02134 became the integer 2134, so a lookup such as df[df["zip"] == "02134"] finds nothing. Second, the amount column became floating point because one value is missing. By default, integer columns that contain missing values are stored as floats. For ordinary amounts that only changes the display (1200 becomes 1200.0). Integers larger than 2 to the 53rd power, however, cannot all be represented exactly as floats, so long numeric IDs can be silently altered.

df = pd.read_csv(
    "customers.csv",
    dtype={"zip": str, "amount": "Int64"},
)

Declaring the types keeps the ZIP code as text and stores amount as a nullable integer, where the missing value appears as <NA> instead of forcing a float column. A similar problem affects literal values that match the default missing-value markers. Examples include the country code "NA" for Namibia, or a field that legitimately contains "null". Passing keep_default_na=False together with na_values=[""] limits missing-value detection to empty fields only.

TSV files and other delimiters

pd.read_csv("data.tsv", sep="\t")
pd.read_table("data.tsv")                       # tab is the default separator here
pd.read_csv("export.csv", sep=";", decimal=",")  # semicolon-delimited, comma decimals
pd.read_csv("report.csv", thousands=",")         # values like "1,200" become numbers

Passing sep=None with engine="python" asks pandas to detect the delimiter. Detection is a guess, so when you know the delimiter, state it.

Encoding problems and malformed rows

A UnicodeDecodeError usually means the file is not UTF-8. Exports saved in Windows-1252, for example, need encoding="cp1252". If the first column name appears with a stray invisible character in front of it, the file probably starts with a byte order mark, and encoding="utf-8-sig" removes it. By default, a row with too many fields raises an error. The on_bad_lines option, available since pandas 1.3, can skip such rows or warn about them, but skipping silently discards data. Fixing the source file, or at least logging which rows were dropped, keeps the loss visible.

Will the result stay readable and usable after copying or sharing?

A DataFrame exists only in memory, so sharing it means either copying its printed form or writing it back to a file. Each route has limits:

  • Printed output truncates long tables and wide columns with ellipses, so it is not a reliable copy of the data.
  • to_csv writes the row index as an extra unnamed first column unless you pass index=False.
  • Written values reflect the parsed types. A leading zero lost on reading stays lost, 1200 may be written as 1200.0, and NaN is written as an empty field unless you set na_rep.
  • Quoting can differ from the original file, because the default writer quotes only the fields that need it.
  • pd.read_clipboard() parses copied tabular text with the same parser, but its default separator is any run of whitespace. A value such as "New York" is therefore split into two fields unless you pass sep="\t" for tab-separated copies. Which separator a given application places on the clipboard was not tested for this article.

Whenever exact values matter, keep the original CSV as the source of record and share that file rather than a re-exported one. read_csv itself does not affect how text is presented to screen readers or other assistive technology. That depends on the format and application used to present the result, and no specific screen reader or spreadsheet application was tested for this review.

A safer starting point for meaning-sensitive files

df = pd.read_csv(
    "customers.csv",
    dtype=str,
    keep_default_na=False,
)
df["amount"] = pd.to_numeric(df["amount"].replace("", None))

This reads every column as text and turns nothing into NaN, so empty fields arrive as empty strings. Each conversion afterward is explicit. It takes more code, but nothing is reinterpreted without your knowledge. For large files, nrows previews the first rows, usecols loads only selected columns, and chunksize processes the file in pieces.

Gaps in this review

No speed or memory measurements were available, and the parser engines (C, Python and pyarrow) were not compared. Defaults also change between pandas releases, as with the string type mentioned above, so confirm the behavior described here against the documentation for the version you have installed.