CSV
ActiveComma-Separated Values is a plain-text tabular format where each row represents a record and each column is separated by a delimiter, typically a comma. Defined by RFC 4180, CSV is the universal interchange format for spreadsheets, databases, and data pipelines.
In one line
CSV (Comma-Separated Values) is defined by RFC 4180 (2005) and registered as MIME type text/csv. Each line is a record; fields are separated by commas. Quoted fields can contain commas, newlines, and double quotes (escaped as ""). CSV has no schema – column meaning comes from a header row by convention. It is the most widely supported tabular data format.
Quick Reference
| Field | Size | Description |
|---|---|---|
| MIME type | text/csv | Registered IANA MIME type. RFC 4180. Use charset=utf-8 parameter for Unicode data. |
| Line ending | CRLF | RFC 4180 mandates CRLF (\r\n). In practice, LF-only is widely accepted by parsers. |
| Delimiter | Comma (,) | Standard delimiter per RFC 4180. TSV (tab-separated) and PSV (pipe-separated) are common dialect variants. |
| Quoting | Double quotes | Fields containing commas, newlines, or double quotes must be enclosed in double quotes. A literal double quote is escaped as "". |
| Header row | Optional | RFC 4180 §3 says the header row is optional but recommended. No formal schema – column names are convention. |
| Encoding | text/csv;charset= | RFC 4180 does not mandate encoding. UTF-8 is the de facto standard. BOM (0xEF 0xBB 0xBF) is added by Excel for UTF-8 signaling. |
| Empty fields | Two commas | An empty field is represented as two consecutive delimiters: a,,b. A field containing only whitespace is not empty. |
Key Characteristics
Tabular structure
Fixed columns per row. Column count must be consistent across all rows per RFC 4180 §3. Parsers vary on handling ragged rows.
No types
All values are strings. Type inference (integer, float, date, boolean) is left to the consuming application. No formal schema.
Dialect fragmentation
RFC 4180 is informational, not mandatory. Excel uses semicolons in some locales. TSV uses tabs. Parsers must handle delimiter variants.
Universal support
Every spreadsheet, database, BI tool, and data science library supports CSV. The lowest-common-denominator interchange format.
Message Format
# RFC 4180 CSV format
# Header row (optional but conventional)
id,name,email,score
1,Alice,[email protected],98.5
2,Bob,[email protected],87
3,"Smith, Carol","[email protected]",92
# Fields with commas must be quoted
4,"O'Brien, Dan","[email protected]",78
# Double quote escaped as ""
5,"Alice ""A"" Jones",[email protected],95# Dialect variants (non-RFC)
id;name;email # Semicolon – Excel in European locales
id name email # Tab-separated (TSV)
id|name|email # Pipe-separated (PSV)
# BOM-prefixed UTF-8 (Excel)
\xEF\xBB\xBFid,name,email
# Python: reading CSV with csv module
import csv
with open('data.csv', newline='', encoding='utf-8') as f:
reader = csv.DictReader(f)
for row in reader:
print(row['name'], row['score'])