How to validate a CSV file's structure before importing it into another system
A quick way to check column names, order, and row counts match what the destination system expects, before a bad import fails partway through.
Before you work through this by hand: you can check your own CSV free and see which of these problems your file actually has — duplicate rows, near-duplicates, broken quoting, encoding damage. It runs in your browser tab, nothing is uploaded, and there's no signup or email.
Why this catches problems earlier
Most of the individual problems covered in our other guides (encoding, delimiters, blank rows, missing values) can also be caught as a group with one upfront validation pass, rather than discovering them one at a time when an import fails partway through, potentially leaving the destination system in a half-updated state.
A basic schema check with pandas
import pandas as pd; df = pd.read_csv('file.csv'); expected_columns = {'id', 'email', 'name', 'company'}; missing = expected_columns - set(df.columns); extra = set(df.columns) - expected_columns; print('missing:', missing, 'extra:', extra) — a quick before-import check for exactly which expected columns are absent and which unexpected ones showed up.
Checking row-level expectations
Beyond column names, it's worth checking type expectations: df['id'].isnull().sum() counts blank IDs (usually a hard requirement), and df['email'].str.contains('@').sum() gives a rough count of values that at least look like emails, as a sanity check rather than full validation.
Comparing row counts against the source
If you know how many rows the source system reported exporting, compare that number against len(df) after loading — a mismatch often means truncation (see our large-file guide) or a parsing error that silently dropped rows.
Make it a repeatable step, not a one-off
If you receive CSV exports from the same source regularly, turning this validation into a short reusable script (rather than manually eyeballing each new file) catches problems before they reach whatever system consumes the import, every time, not just when you remember to check.
See CSV Repair & Deduper (offline browser tool) — $19 one-time