Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Parsing · CSV

Direct answer

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.

When to use this

Use this when CSV files must be parsed reliably, including quoted fields and encodings.

First 30 seconds

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.

Operational verification

CSV → library parser → validated records

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
CSV interchange automation
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformCSV interchange automation · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior.
Scope / prerequisiteUse this when CSV files must be parsed reliably, including quoted fields and encodings.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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 references

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.

observation · 1
Key points
  • Use Import-Csv or Python's csv module, not string splitting.
  • Quoted fields can contain commas and newlines.
  • Check encoding and BOM.
Key checks
  • python3 -c 'import csv;list(csv.reader(open("f.csv",newline="",encoding="utf-8-sig")))' — robust parse
  • Import-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
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docCSV interchange automation current

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%
Depth when you need it

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.

Confirmation

Confirm action

Continue?