pandas read_csv errors: UnicodeDecodeError, ParserError and other fixes

Updated November 26, 2026

pd.read_csv() works on clean files and fails, or quietly reads the wrong thing, on the rest. These are the errors and surprises that come up most, with the argument that fixes each one. The examples assume pandas 2.x.

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9

The file isn’t UTF-8. A byte like 0xe9 (é) or 0x96 (a dash) usually means Windows-1252, the encoding Excel uses for plain CSV on Western systems:

df = pd.read_csv("data.csv", encoding="cp1252")

If you don’t know the encoding, encoding_errors="replace" lets the read finish and puts � where a byte couldn’t be read, so you can see which rows are affected. See the CSV encoding guide for converting the file itself.

KeyError: 'id' when the column is clearly there

Check df.columns. If the first name prints as '\ufeffid', the file starts with a byte order mark (BOM), which Excel adds to UTF-8 files. Read it with encoding="utf-8-sig", which removes the BOM. Names with spaces at the end ('id ') cause the same error: df.columns = df.columns.str.strip().

ParserError: Expected 3 fields in line 4, saw 5

A row splits into more fields than the header, almost always because a value contains a comma and isn’t quoted. To see the bad rows without stopping the read:

df = pd.read_csv("data.csv", on_bad_lines="warn")   # prints each skipped line

on_bad_lines="skip" drops them silently, which loses data. Fixing the quoting is better. The “Expected N fields” guide shows how.

ParserError: EOF inside string starting at row 12

A value opens a quote that never closes, so pandas reads to the end of the file looking for it. Look at the row it names for a stray ", such as 55" TV in an unquoted field.

Everything ends up in one column

The file uses another separator, usually a semicolon from a European Excel. Pass it, or let pandas detect it:

df = pd.read_csv("data.csv", sep=";")
df = pd.read_csv("data.csv", sep=None, engine="python")  # sniffs the separator

Semicolon files usually have decimal commas too: add decimal="," and thousands=".", or 1.299,50 is read as text.

Leading zeros disappear, or IDs become 1.234e+15

pandas guesses that 02134 is a number and stores 2134. Long IDs become floats, and an integer column with a blank cell becomes float too (42 turns into 42.0). Tell it the types:

df = pd.read_csv(
    "data.csv",
    dtype={"zip": str, "order_id": str, "quantity": "Int64"},
)

"Int64" (capital I) is pandas’ integer type that allows missing values. If the zeros were already lost before pandas, for example after the file passed through Excel, see leading zeros.

DtypeWarning: Columns (3) have mixed types

pandas reads large files in chunks and guessed different types for that column in different chunks. Set the column’s dtype as above. low_memory=False silences the warning but still guesses.

Dates read as text, or day and month swapped

df = pd.read_csv("data.csv", parse_dates=["created"], date_format="%d/%m/%Y")

Without date_format, pandas guesses the format, and 03/04/2026 may become March 4. Rows that don’t match the format stay as text, which df.dtypes shows as object.

Empty strings become NaN, or “NA” becomes NaN

By default pandas turns blank cells and words like NA, null and N/A into NaN. That’s a problem for a country column with Namibia (NA). Use keep_default_na=False and list your own markers with na_values=[""].

Find the problems before you write code for them

Most of the errors above come from the file, not from pandas. Drop it into CSVCheck to see its encoding, separator, BOM, broken quotes and rows with the wrong number of fields, each with its line number. It runs in your browser, so the data stays on your computer.

More CSV guides