Disclosure: I wrote this article with AI assistance. I work with ExtractHelp, a data services agency. The tutorial below is self-contained and uses fictional sample data.
A CSV conversion can look successful and still be wrong. The file opens. The columns look right. Then the import fails, or worse, it succeeds with missing rows, shifted values, or product codes that lost their leading zeros.
The safe habit is simple: check the conversion before you import it. Count parsed records, compare the header, check one total, and sample a few rows against the source. This short Python check catches the common failures without any extra packages.
Why counting lines is not enough
Do not count raw lines in the file. A quoted CSV cell can contain a line break, so one record can span two physical lines. A line count can say the file is complete when a record is missing, or warn about a problem that is only a quoted note field.
Use a CSV parser instead. Python's built-in csv module reads records correctly, including quoted commas and quoted line breaks.
Step 1: Count records with a parser
Save this as check_csv.py. It expects a source record count, then compares it with the number of data records in the converted CSV.
import csv import sys def check_csv(path, expected_rows, expected_header): with open(path, newline="", encoding="utf-8-sig") as f: reader = csv.reader(f) header = next(reader, None) if header != expected_header: raise SystemExit(f"Header mismatch: expected {expected_header}, got {header}") rows = list(reader) if len(rows) != expected_rows: raise SystemExit(f"Row mismatch: expected {expected_rows}, got {len(rows)}") for number, row in enumerate(rows, start=2): if len(row) != len(expected_header): raise SystemExit(f"Record {number} has {len(row)} cells, expected {len(expected_header)}") print(f"PASS: {len(rows)} data rows, {len(expected_header)} columns") if __name__ == "__main__": check_csv("converted.csv", expected_rows=3, expected_header=["sku", "name", "price"]) The header check matters as much as the row count. If a converter builds columns from the first source record only, a field that appears later can disappear quietly. Compare the full expected header, not just the first few columns.
Step 2: Check one total that should not change
Row counts prove that records survived. They do not prove that values survived. Pick one numeric column that should keep the same total after conversion, such as price, quantity, or amount, and compare it with the source total.
Use decimal arithmetic for money, not floating point. A small script can sum the column as Decimal values and fail if the converted total differs from the source total. If the total changes, stop and inspect the mapping before importing.
Step 3: Protect codes, dates, and text
Three conversion mistakes cause quiet damage:
- Leading zeros: product codes such as
001245must stay text. If a spreadsheet treats them as numbers, the zeros disappear. - Long IDs: long numeric IDs can be rounded by spreadsheet software. Keep them as text.
- Dates: convert dates only when the source format is known. A value such as
06/07/2026can mean 6 July or June 7, so guessing swaps day and month.
A good check samples rows that contain codes, IDs, dates, accented text, and quoted notes. Compare those exact values with the source before you trust the file.
Step 4: Sample records against the source
Finally, read a small sample: the first record, a middle record, the last record, and any record with unusual characters. Check that each value sits under the right header and matches the source.
This sample step catches shifted cells that a row count cannot see. It also catches encoding problems, where accented letters turn into symbols after conversion.
Common mistakes to avoid
- Counting lines instead of records. Quoted line breaks make line counts unreliable.
- Trusting the first record's columns. A field that appears only in later records can be dropped.
- Checking rows but not totals. The right number of rows can still contain wrong values.
- Letting codes become numbers. Leading zeros and long IDs need text handling.
- Guessing date formats. Convert dates only when the source format is known.
Conclusion
A CSV conversion is ready to import when four checks pass: the parsed record count matches the source, the header matches the expected fields, one important total is unchanged, and sampled records match the source exactly.
If your files arrive in mixed formats and need mapping to a system template, ExtractHelp's Data Conversion service converts between formats such as PDF, Excel, CSV, JSON, XML and databases, with row counts, totals and samples checked against the source.

