Use this when CSV files must be parsed reliably, including quoted fields and encodings.
Parsing · CSV
Parse CSV with a real parser, such as Import-Csv -Delimiter or Python's csv module, not by splitting on commas, so quoted fields, embedded newlines and encodings like UTF-8 with BOM are handled.
1. Parse CSV with libraries (csv, pandas, Import-Csv).
2. Handle quotes, embedded newlines, BOM.
3. Validate after parsing.
4. Report bad rows with line numbers.
5. Stream large files.
CSV → library parser → validated records
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
The negative fixture should deliberately exercise risks such as encoding/BOM issues, delimiter/quoting ambiguity, duplicate keys, namespace drift, scalar coercion, invalid schema assumptions and parser success without consumer-valid semantics, choosing the cases most relevant to decoding/lexing/structural parse, schema validation, error location and preventing parser success from being treated as business-semantic validity.
Step 2 Common mistakes Narrow the fault
- Splitting on commas manually (quoted fields break).
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Use Import-Csv or Python's csv module, not string splitting.
- Quoted fields can contain commas and newlines.
- Check encoding and BOM.
python3 -c 'import csv;list(csv.reader(open("f.csv",newline="",encoding="utf-8-sig")))'— robust parseImport-Csv file.csv -Delimiter ';'— PowerShell- Don't split on commas manually — quoting
ReferenceWhy it matters1 section · depth on demand
In depth
Parsing CSV turns lines of text into records with named fields. Use a proper CSV library, which handles quoting, embedded delimiters and line breaks inside fields correctly.
import csv
errors = []
with open("vlans.csv", newline="", encoding="utf-8-sig") as f:
for n, row in enumerate(csv.DictReader(f), start=2):
try:
vid = int(row["vid"])
assert 1 <= vid <= 4094
except (ValueError, AssertionError, KeyError):
errors.append(f"line {n}: invalid vid {row.get('vid')!r}")
mlr --icsv --opprint filter '$site == "oslo"' devices.csv # Miller
All CSV values are strings; convert types explicitly and report errors with line numbers so the data owner can fix the source.
ReferenceImportant terms & boundaries1 section · depth on demand
Mechanics
The linked authority for bounded mechanics is RFC 4180 — Common Format and MIME Type for CSV Files; documentation support is separate from observed lab/production Evidence.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in CSV > Parsing. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.rfc-editor.org/rfc/rfc4180 · confidence 94%Deep reference
Healthy vs suspicious evidence
Output interpretation
For decoding/lexing/structural parse, schema validation, error location and preventing parser success from being treated as business-semantic validity, prefer typed fields and stable IDs over human presentation text.