Semicolon-Delimited CSV: How to Detect the Dialect
A practical guide to CSV files that use a semicolon separator: what a CSV dialect is, why semicolons appear, and how to detect and verify the field delimiter safely.
A file named .csv does not always use commas. Many CSV files use a semicolon as the field delimiter. If you open one with the wrong assumption, every row can collapse into a single column, or values can be split in the wrong places. This guide explains what detecting a CSV dialect does for your text and how to identify a semicolon separator before you parse or convert the file. It also shows how to check the result so meaningful content stays unchanged.
What dialect detection does for your text
A CSV dialect is the set of formatting rules a delimited file follows. Dialect detection, whether done by a tool, a library function, or by hand, examines a sample of raw text and infers those rules. It does not change the file. Its output is a description of the format, which a parser then uses to split each line into the correct fields.
The input is plain delimited text. The output is a set of parsing settings. The effect is that fields are read as the author intended, so names, addresses and numbers containing punctuation are not cut apart or merged.
A dialect typically covers these properties:
- Field delimiter: the character that separates values, such as a comma, semicolon, tab or pipe.
- Quote character: usually the double quote, which wraps fields that contain the delimiter, quotes or line breaks.
- Quote escaping: how a literal quote is written inside a quoted field. The common convention is to double it ("").
- Line terminator: the line ending used, such as LF or CRLF.
- Header row: whether the first line holds column names rather than data.
Two related properties are not part of the CSV structure but often decide whether the data is read correctly. The first is character encoding, including whether the file starts with a byte order mark (BOM), an invisible marker some programs add to UTF-8 files. The second is the decimal separator inside numeric values.
Why some CSV files use a semicolon separator
RFC 4180, the commonly cited description of CSV, uses the comma as the separator. In practice, many applications choose the delimiter from the system's regional settings. In locales where the comma is the decimal separator, a comma delimiter would clash with numbers such as 3,14. Spreadsheet software in those locales often exports CSV with semicolons instead. A file can therefore be valid by its producer's rules and still fail to open correctly elsewhere.
Some spreadsheet programs, notably Microsoft Excel, recognize an optional first line such as sep=; as a hint about the delimiter. This is an application-specific convention, not part of the CSV standard. Other parsers may treat that line as ordinary data.
Example: why the delimiter is not always obvious
The following sample is illustrative and was written for this guide. It is not output from a specific tool.
Name;City;Amount
"Müller, Anna";Berlin;1.234,50
Smith;"New York; NY";99,90
Commas appear in this sample, but only inside a quoted name and inside decimal numbers. A semicolon also appears inside a quoted city. If you ignore quoted text, each line contains exactly two semicolons. That gives three fields on every row, which marks the semicolon as the delimiter. Counting raw characters without respecting quotes would give misleading results for both candidates.
How to detect the field delimiter step by step
- 1. Open the file in a plain-text editor, not a spreadsheet. A spreadsheet applies its own guess and hides the raw separators.
- 2. Check the first line for a sep= hint. If one is present, note it and decide whether your parser should skip that line.
- 3. Count each candidate delimiter (semicolon, comma, tab, pipe) on several lines, ignoring characters inside double quotes. The true delimiter gives the same count on every data row.
- 4. Confirm the quoting rules. Look for fields wrapped in double quotes and for doubled quotes ("") inside them.
- 5. Look at numeric columns. Values such as 99,90 or 1.234,50 suggest a decimal comma, which usually goes together with a semicolon delimiter.
- 6. Check the encoding. If the first column name shows stray characters at the very start, the file may begin with a UTF-8 BOM that your reader is not stripping.
- 7. Parse the file with the delimiter set explicitly, then check that every row has the same number of fields as the header.
Detecting the dialect with Python's csv module
Python's standard library includes csv.Sniffer, which inspects a text sample and returns a dialect object. You can limit the candidates it considers through the delimiters argument. Sniffer is heuristic. It can guess wrong on short or unusual samples, and it raises csv.Error when it cannot determine a delimiter. Treat its answer as a suggestion to verify. The snippet below is an untested example.
import csv
with open("data.csv", newline="", encoding="utf-8-sig") as f:
sample = f.read(4096)
f.seek(0)
try:
dialect = csv.Sniffer().sniff(sample, delimiters=";,\t|")
except csv.Error:
dialect = None # fall back to an explicit choice, e.g. delimiter=";"
reader = csv.reader(f, dialect) if dialect else csv.reader(f, delimiter=";")
rows = list(reader)
widths = {len(r) for r in rows}
print("delimiter:", repr(dialect.delimiter) if dialect else "';' (fallback)")
print("field counts seen:", widths)
In the snippet, the utf-8-sig encoding strips a leading BOM if one exists. Opening the file with newline="" lets the csv module handle line breaks inside quoted fields itself. If the final check reports more than one field count, the detected delimiter or quoting is likely wrong, or the file has malformed rows that need a closer look.
A quick command-line check and its limits
For a rough first look, you can count fields per line with awk, using the semicolon as the separator. This shows how many lines have each field count.
awk -F';' '{print NF}' data.csv | sort | uniq -c
This check does not understand quoting. A semicolon inside a quoted field, like "New York; NY" in the earlier example, inflates the count for that line. Quoted fields that span several lines also break the per-line view. Use it to spot a likely delimiter, then confirm with a CSV-aware parser.
Common symptoms and what they usually mean
| Symptom | Likely cause | What to check |
| Each row appears in a single column | Parser expects commas, file uses semicolons | Set the delimiter to ; explicitly |
| Names or addresses split into extra columns | Delimiter correct, but quotes not honored | Confirm the quote character and that the parser handles quoting |
| Numbers read as text or split in two | Decimal comma read with a comma delimiter | Use the semicolon delimiter and convert decimals deliberately |
| First header name has odd leading characters | UTF-8 BOM not stripped | Read with a BOM-aware encoding setting |
| First row is sep=; | Excel-style delimiter hint | Skip that line if your parser does not support it |
Changing the delimiter without damaging content
If your goal is to turn a semicolon-delimited file into a comma-delimited one, do not use a plain find-and-replace. Replacing every ; with , would alter semicolons inside quoted text and collide with decimal commas, silently corrupting values. Instead, parse the file with the correct dialect and write it back out with the new delimiter, letting the CSV writer add quotes where a field now contains a comma. Afterwards, compare the row count and the field count per row between the original and the converted file.
Treat decimal separators as a separate decision. A CSV writer will not convert 99,90 to 99.90 on its own. If the target system expects a decimal point, convert numeric columns explicitly and leave text columns untouched.
Verifying the result
- Every row has the same number of fields as the header.
- Fields with embedded delimiters or quotes, such as "Müller, Anna", appear intact in one column.
- The first column name has no stray leading characters.
- Numeric columns hold the values you expect, with the intended decimal separator.
- The total number of records matches the source, counting records rather than physical lines, since quoted fields may contain line breaks.
Gaps in this guide
No source material was supplied on specific detection tools, their accuracy, or how particular applications behave in particular locales. The steps above rely on general CSV conventions and the documented behavior of Python's standard csv module. Before relying on a specific spreadsheet program, online converter or library, check its own documentation for delimiter detection and encoding handling.