CSV rows with the wrong number of fields

Every row of a CSV file is expected to have as many fields as the header. A row with more fields usually contains an unquoted delimiter; a row with fewer is missing a value or was split across lines. Readers differ in strictness: pandas and PostgreSQL stop, while spreadsheet apps silently shift data into the wrong columns. PasteKit flags each ragged row as a warning and still shows the table.

Seen as:

  • pandas.errors.ParserError: Error tokenizing data. C error: Expected 3 fields in line 3, saw 4
  • Too many fields: expected 3 fields but parsed 4
  • ERROR: extra data after last expected column
  • ERROR: missing data for column "city"
  • Row 4 doesn't contain data for all columns

Input

Settings

History

Load from URL

Common causes

1. A delimiter inside an unquoted value

Addresses, numbers with thousands separators and free text often contain commas. Any field that contains the delimiter must be wrapped in double quotes.

Before
id,name,city
2,Grace,New York, NY
After
id,name,city
2,Grace,"New York, NY"

2. A missing value at the end of a row

Empty trailing fields still need their commas. A row that stops early has fewer fields than the header.

Before
id,name,city
3,Linus
After
id,name,city
3,Linus,

3. The wrong delimiter

Excel in many European locales saves “CSV” with semicolons because the comma is the decimal separator. A comma-based reader then sees one field per row, or splits decimals. Tell the reader the delimiter (sep=";" in pandas); PasteKit detects it automatically.

Before
id;name;price
1;Ada;3,50
After
id,name,price
1,Ada,"3,50"

4. Title or notes above the header

Report exports often start with a title line or a blank line, so the first “row” has one field and every data row looks too long. Remove the preamble, or skip it (skiprows=1 in pandas).

Before
Sales report 2026
id,name
1,Ada
After
id,name
1,Ada

Frequently asked questions

Which line is "line 3" in the pandas message?

pandas counts physical lines from 1, including the header. Quoted fields that span lines shift the count, so look at the row content PasteKit highlights rather than counting by hand.

How do I skip bad rows instead of failing?

In pandas 1.3 and later, pass on_bad_lines=“skip” (or “warn”). Skipped rows are lost silently, so prefer fixing the quoting when you can.

Is a ragged CSV file invalid?

RFC 4180 says each line should contain the same number of fields. Some tools accept ragged rows, but any import into a database table needs consistent columns.

Related