Data guide

How to clean a CSV before importing it into another system

CSV looks simple until inconsistent delimiters, duplicate records, embedded line breaks, and malformed headers cause a partial or incorrect import. Validate the structure before transforming the data.

Key takeaways

  • Keep an untouched source export and clean a copy so every transformation is reversible.
  • Parse CSV according to its delimiter and quoting rules instead of splitting lines and commas manually.
  • Validate a small import first and reconcile row counts before committing the full dataset.

Comma-separated values are not always separated by commas. Depending on locale and source application, a file may use semicolons or tabs. Quoted fields may contain delimiters, escaped quotation marks, and even line breaks. A cleanup process that treats CSV as plain lines can silently move values into the wrong columns.

The goal is not merely to make the file look tidy. It is to preserve meaning while producing a structure the destination system can interpret consistently.

Preserve the source and define the target

Keep the original export unchanged. Create a working copy and write down the destination requirements before editing:

  • accepted delimiter and character encoding;
  • whether a header row is mandatory;
  • required column names and order;
  • maximum field lengths;
  • accepted date, decimal, and boolean formats;
  • how missing values should be represented;
  • which columns form a unique record key.

Without a target definition, “clean” is subjective. Removing blank fields might improve appearance while making a required value impossible to distinguish from an intentionally empty one.

Parse before changing values

Open the file in CSV Cleaner and confirm the detected or selected delimiter. Inspect the preview for a stable column count. If one row suddenly has more columns, the source may contain an unquoted delimiter. If a row appears to break in the middle of an address or note, it may contain an embedded newline that requires correct quoting.

Avoid using a simple text replacement to change every comma to a semicolon. That can corrupt commas inside quoted values. A CSV parser should interpret the records and then serialize them with the chosen output delimiter.

Normalize headers deliberately

Headers are identifiers, not decorative labels. Common import failures include trailing spaces, duplicate names, unexpected punctuation, and capitalization differences such as CustomerID versus customer_id.

A sensible header policy might:

  1. trim surrounding whitespace;
  2. make every name unique;
  3. map known source names to exact destination names;
  4. retain a written mapping for audit and repeatability.

Do not automatically lowercase headers when the destination is case-sensitive. Do not rename a column unless its meaning is understood.

Clean whitespace without destroying content

Trimming leading and trailing whitespace is often safe for names, codes, and email addresses. Removing internal whitespace is different. New York, ACME Europe, and a fixed-width identifier may rely on spaces.

Also distinguish blank from zero and false:

  • an empty value may mean “unknown”;
  • 0 is a number;
  • false is a boolean-like value;
  • NULL may be text or a database null marker depending on the import contract.

Test the destination’s interpretation rather than guessing.

Handle duplicates using a business key

Two identical rows are easy to identify, but most real duplicates differ in one field. A customer may appear twice with the same account number and a different phone format. A transaction may share a date and amount with another legitimate transaction.

Choose the fields that define identity in the destination system. Examples include:

  • a stable external customer ID;
  • invoice number plus supplier ID;
  • SKU plus warehouse;
  • event ID generated by the source.

CSV Duplicate Remover lets you select one or more parsed columns as a composite key and keeps the first matching record. Remove Duplicate Lines remains appropriate for genuinely line-oriented lists, not structured CSV.

Split and combine batches without losing the schema

When an importer caps rows per upload, use CSV Splitter to create consistently sized parts that repeat the header row. Record the generated part count and verify that the sum of their data rows still matches the cleaned source.

For exports produced in batches, CSV Merger aligns columns by header name before appending rows. Do not merge files merely because they have the same number of columns: confirm that the names and meanings match. If there is no header row, every file must already use exactly the same column order.

Use JSON as an inspection format

CSV to JSON can make record boundaries and missing fields more obvious. JSON is also useful when the destination exposes an API or when you need to inspect nested serialization decisions.

The reverse operation, JSON to CSV, requires a flat table. Nested objects and arrays need an explicit policy: serialize them as JSON text, flatten selected properties, or move them to a separate related table. No automatic conversion can infer the correct business meaning.

Watch for spreadsheet interpretation

Spreadsheet applications may reinterpret imported values:

  • long identifiers can become scientific notation;
  • leading zeros can disappear;
  • dates can switch day and month;
  • values beginning with =, +, -, or @ may be treated as formulas;
  • decimal commas can conflict with comma delimiters.

If the CSV will be opened by humans in spreadsheet software, test that path separately from the system import. A file can be structurally valid CSV and still display misleadingly in a spreadsheet.

Validate with counts and a small import

Before the full import, record:

  • source row count;
  • cleaned row count;
  • number of rejected or removed rows;
  • duplicate count and rule used;
  • count of missing required fields.

Import a small representative sample containing ordinary values and edge cases. Confirm the result in the destination, then import the full file. Reconcile the destination count afterward and retain the original, cleaned output, mapping rules, and import report according to your data-retention policy.

Local browser processing prevents the file from being sent to a conversion backend, but the downloaded result is still sensitive data. Store and transmit it according to the same rules as the source.