Test files › Structured data › ragged-rows.csv
CSV with ragged, uneven rows
Rows with too few and too many columns relative to the header.
↓ Download ragged-rows.csv| Filename | ragged-rows.csv |
| Format | CSV |
| Size | 123 bytes (123 bytes) |
| MIME type | text/csv; charset=utf-8 |
| SHA-256 | 2292b423c8910544ee2df0a720e17cfaebb15f10270c0dd64e39bfc411635cb4 |
What this file catchesImporters that silently pad or drop values. The right behaviour is a per-row validation error naming the row number, not a partial import.
Handle it in code
Each snippet below was run against this exact file with Python 3.14.4 and Node 24.15.0 when this page was built, and the output shown is what it printed.
Python
Sniff the dialect from a sample, then stream the rows and compare each with the header. The csv module handles quoted commas and newlines inside fields, which is exactly what a split(',') gets wrong. line_num is the physical line, so it stays right when a field spans lines.
import csv
with open("ragged-rows.csv", newline="", encoding="utf-8-sig") as f:
try:
dialect = csv.Sniffer().sniff(f.read(64 * 1024), delimiters=",;\t|")
except csv.Error:
dialect = csv.excel # the sniffer gives up on irregular files: assume commas
f.seek(0)
rows = csv.reader(f, dialect)
header = next(rows)
count, bad = 0, []
for count, row in enumerate(rows, 1):
if len(row) != len(header):
bad.append((rows.line_num, len(row)))
print(f"delimiter {dialect.delimiter!r}, {len(header)} columns, {count:,} data rows")
for line, n in bad[:5]:
print(f" line {line}: {n} field{'s' * (n != 1)}, expected {len(header)}")
if not bad:
print(" every row matches the header")Run against this file, it prints: delimiter ',', 3 columns, 5 data rows
line 3: 2 fields, expected 3
line 4: 5 fields, expected 3
line 6: 1 field, expected 3
Related guides and tools
Download & verify
curl -fsSL -o "ragged-rows.csv" "https://files.hexaqa.com/csv/ragged-rows.csv"
curl -fsSL "https://files.hexaqa.com/csv/ragged-rows.csv" | sha256sum
# expect: 2292b423c8910544ee2df0a720e17cfaebb15f10270c0dd64e39bfc411635cb4