Skip to content

Explicit headers · Predictable output

Merge CSV files

Combine two or more CSV files. Require an exact header match or deliberately create an ordered union.

Merge CSV files locally

Choose two or more files, up to 50 MB combined. Nothing is uploaded.

Append rows from each file in order. This does not join records by an ID.

  1. Choose CSV files

    Select two or more files, up to 50 MB combined, or try the samples.

  2. Check headers and order

    Use Strict match or Header union; arrange the files in the row order you need.

  3. Download merged CSV

    Check the merged preview, then save one CSV with its header and appended rows.

Predictable by default

No silent column shifts

Strict mode prevents a value from sliding under the wrong column just because one file changed header order. Union mode is available when files intentionally contain different columns.

Union mode requires unique, nonblank headers in every file. That makes the mapping explicit instead of guessing which duplicate or blank column a value belongs to.

If your destination limits records per upload, download the merged CSV and split it into smaller CSV files. Repeat the header in each part so you can import the files separately.

Plain answers

CSV merge questions

What is strict header matching?

Every file must have exactly the same source headers in the same order. A mismatch names the file that needs attention and blocks the download.

How does header union work?

Union mode keeps headers in first-seen order, maps cells by exact header text, and leaves a cell empty when a file does not contain that header.

How does merging work?

Choose two or more CSV files, require matching headers or select an ordered header union, then download the combined CSV.

Other ways to work with your CSV

Use these local examples when you prefer a script or SQL. They create separate results and explain where their behavior differs from this browser tool.

Append CSV files with matching headers using Python

Appends first.csv then second.csv with one header, preserving cell text and parsed record order. It refuses to overwrite merged.csv.

Before you start

  • Python 3.10 or later. Run in a working folder with a backup of your source; output files may be replaced unless opened in exclusive mode.
  • Place first.csv and second.csv in that folder. Examples use UTF-8, a comma delimiter and a header row. Column-specific recipes use id,label,amount,status,note; adapt names to your file.
Run the complete Python example
python3 - <<'PY'
import csv

paths = ["first.csv", "second.csv"]
with open("merged.csv", "x", encoding="utf-8", newline="") as target:
    writer = csv.writer(target)
    headers = None
    for path in paths:
        with open(path, encoding="utf-8-sig", newline="") as source:
            reader = csv.reader(source, strict=True)
            current = next(reader, None)
            if current is None:
                raise ValueError(f"{path}: missing header")
            if headers is None:
                headers = current
                writer.writerow(headers)
            if current != headers:
                raise ValueError(f"{path}: header names/order differ")
            for row in reader:
                if len(row) != len(headers):
                    raise ValueError(f"{path}: wrong field count")
                writer.writerow(row)
print("Wrote merged.csv")
PY

Limits and output

  • CSV has no stored type schema. Python keeps fields as strings until an example explicitly converts a value. These recipes do not add spreadsheet formula protection; import sensitive-looking strings as text in spreadsheets.
  • This is strict append, not a key join or header union. A late validation error may leave a partial merged.csv; remove it before retrying after fixing the source.

Documentation: Python CSV reader and writer

Use DuckDB for CSV merge

Run SQL locally with the DuckDB command line. Read fields as text, then cast only the columns used in calculations.

Before you start

  • Install the DuckDB command-line client using its official installation guide.
  • Run beside first.csv and second.csv. Named-column examples expect id,label,amount,status,note.
Run DuckDB SQL
duckdb <<'SQL'
COPY (SELECT * FROM read_csv(['first.csv', 'second.csv'], header = true, all_varchar = true, force_not_null = ['id', 'label', 'amount', 'status', 'note'], union_by_name = true)) TO 'duckdb-output.csv' (HEADER, DELIMITER ',');
SQL

Limits and output

  • Adapt column names and casts to your input. DECIMAL(18,4) rounds to four fractional digits; values outside its range become NULL with TRY_CAST. SQL output order is not promised without ORDER BY; equal sort keys need an explicit tie-breaker for a deterministic order.
  • This is a name-based header union; missing fields become NULL. It differs from strict append, and file order is not a stable row-order guarantee.
  • These recipes write ordinary CSV without spreadsheet formula protection.

Documentation: DuckDB CSV options and installation; DuckDB COPY export