Prompt
My CSV dataset won't import cleanly into pandas, what should I check?
Latest observation
Oct 16, 2026
OpenAI APIWeb search: off
If a CSV won’t import cleanly into pandas, the issue is usually one of these:
1) Delimiter mismatch
Your file may not be comma-separated.
- Common alternatives:
;,\t,| - Try:
pd.read_csv("file.csv", sep=";")
2) Quoting issues
Embedded commas, quotes, or newlines in text fields can confuse parsing.
- Look for unmatched quotes
- Try specifying quote handling:
import csv
pd.read_csv("file.csv", quotechar='"', quoting=csv.QUOTE_MINIMAL)
3) Inconsistent number of columns
Some rows may have too many or too few fields.
- This often causes
ParserError - Check for:
- extra delimiters in a row
- missing values without proper separators
- malformed lines
4) Encoding problems
The file may not be UTF-8.
- Common encodings:
latin1,cp1252
pd.read_csv("file.csv", encoding="latin1")
5) Mixed data types
A column may contain both numbers and strings, causing type inference issues.
- Force object/string:
pd.read_csv("file.csv", dtype={"colname": str})
6) Header or index confusion
The first row may not actually be the header.
- Try:
pd.read_csv("file.csv", header=None)
7) Bad line handling
Some rows may be malformed, and you may want to inspect or skip them.
pd.read_csv("file.csv", on_bad_lines="warn") # or "skip"
8) Whitespace problems
Extra spaces around separators or values can matter.
pd.read_csv("file.csv", skipinitialspace=True)
9) Missing values or special placeholders
Your file may use NA, NULL, -, etc.
pd.read_csv("file.csv", na_values=["NULL", "-", ""])
10) File corruption or export issues
Sometimes the CSV is simply malformed:
- truncated file
- broken line endings
- exported from Excel or another tool with odd formatting
Quick debugging steps
- Open the file in a text editor and inspect a few lines.
- Read a small sample:
pd.read_csv("file.csv", nrows=5)
- Print raw lines to spot malformed rows.
- If needed, use the Python engine, which is more flexible but slower:
pd.read_csv("file.csv", engine="python")
If you want, paste:
- the exact error message
- a few lines from the CSV
- your
read_csv()call
and I can help pinpoint the problem.