How can I handle CSV files that use a semicolon instead of a comma?
Quick answer
If you know the file uses semicolons between fields, tell Python’s CSV reader explicitly with delimiter=';'. Open the file with newline='', read its rows, and inspect the first few results and their column counts. If the delimiter is only a guess from a small sample, don’t treat that guess as confirmation; verify the format from a reliable description or the file’s producer.
The question, the details, the next step.
A practical checklist
Confirm the delimiter from a reliable file description or export setting when possible.
Open the file with
newline=''and pass the known separator asdelimiter=';'.Inspect the header and several representative parsed rows.
Compare row lengths with the expected column count and review any mismatches.
Treat sample-based delimiter detection as a guess until verified.
A few more useful answers
Why does a semicolon file show up as one column?
The CSV reader uses a comma by default. If the file’s fields are separated by semicolons, specify delimiter=';' when creating the reader. [S1]
Should I use Python’s Sniffer instead of specifying the delimiter?
Use Sniffer only when the format is uncertain, and treat its result as a guess. Verify it against reliable information about the file and inspect parsed rows; a sample alone does not confirm the format. [S1]
What does `newline=''` do in the file-opening example?
It follows the CSV module’s documented guidance for opening file objects used with its reader. [S1]
Sources
References used for this guide.
- [S1] Python 3.14 csv — CSV File Reading and Writing docs.python.org · Checked
