How to Combine Multiple CSV Files Into One When Columns Differ

Stack monthly exports into one CSV even when headers are in a different order, spelled differently or missing. Includes PowerShell, csvkit and pandas.

Updated September 29, 2026 6 min read

Use the free CSV MergerCombine multiple CSV files into one, matching columns by header

Exports rarely arrive as one file. Your e-commerce platform gives you one order file per month, three regional offices each send a contact list, a survey tool splits responses by week. To analyse the whole picture, you need a single table with every row.

Stacking files sounds trivial, and it is when every file has identical headers in identical order. In practice, a column was added in March, another office writes Email instead of email, and one file uses semicolons. This guide explains the difference between appending and joining, how to line up columns that don't match, and several ways to do it: in the browser, on the command line and in Python.

Appending versus joining

There are two different operations people call "merging CSV files":

  • Appending (stacking) puts the rows of file B under the rows of file A. The files describe the same kind of record, like orders from different months. The row count grows; the columns should stay the same.
  • Joining matches rows from file A with rows from file B using a shared key, like adding each customer's country from a second file. The row count stays roughly the same; the columns grow.

This guide is about appending. Joining is a lookup job for a spreadsheet (XLOOKUP), a database or pandas.merge.

The hard part: lining up the columns

Appending blindly, row by row, only works when every file has exactly the same header. Otherwise values slide into the wrong columns. Consider three files:

january.csv    email,name,plan
february.csv   Name,Email,Country
march.csv      email;name;plan

A careful merge treats these as one table with the columns email, name, plan and Country:

  • Match by header name, not position. February's second column is Email, and its values belong under email, even though it sits in position two.
  • Normalise the names. Email, email and email are the same column once case and surrounding spaces are ignored.
  • Take the union of columns. plan is missing from February and Country is missing from January and March. Those cells stay empty rather than causing an error.
  • Detect the delimiter per file. March uses semicolons; it still has to be parsed correctly.

After merging, you often also want to remove rows that appear in more than one file (a customer exported twice), and to know which file each row came from.

Merge CSV files in your browser

The CSV Merger does all of the above locally, without uploading the files.

  1. Open the CSV Merger and drop two or more CSV files onto the upload area. Load 3 sample files loads the example above.
  2. Reorder the files with the up and down arrows if the row order matters. Rows are added in list order.
  3. Keep Match headers ignoring case & spaces on so Email and email become one column. Switch it off if differently-cased headers really are different fields.
  4. Keep Remove duplicate rows on to drop rows that are identical across all columns.
  5. Turn on Add source_file column if you want to know where each row came from.
  6. Choose the Output delimiter, check the Files, Rows read, Duplicates removed and Columns tiles, then click Download merged CSV or copy the result.

The delimiter of each input file is detected automatically. The first spelling of a header is the one used in the output, and columns appear in the order they are first seen.

Other ways to merge CSV files

Windows PowerShell

PowerShell parses CSV properly and matches columns by name:

Get-ChildItem .\exports\*.csv |
  ForEach-Object { Import-Csv $_.FullName } |
  Export-Csv .\merged.csv -NoTypeInformation -Encoding UTF8

One catch: Export-Csv takes its columns from the first object it receives, so columns that exist only in later files are silently dropped. It works well when every file has the same columns, possibly in a different order. Import-Csv also matches headers without regard to case. In Windows PowerShell 5.1, -Encoding UTF8 writes a BOM; PowerShell 7 defaults to UTF-8 without one.

The old copy *.csv merged.csv trick in Command Prompt just concatenates bytes, so every file's header row ends up in the middle of the data.

csvkit (macOS, Linux, Windows with Python)

The csvkit command csvstack is built for this job and fills missing columns with blanks:

csvstack -g january,february,march -n source_file january.csv february.csv march.csv > merged.csv

The -g and -n options add a column naming the source of each row. Header matching is exact, so tidy header spelling first.

awk for identical files

When all files share exactly the same header and contain no quoted line breaks, a one-liner keeps the first header and skips the rest:

awk 'FNR==1 && NR!=1 { next } { print }' *.csv > merged.csv

It is fast on very large files, but it knows nothing about columns, so any difference in header order silently produces wrong data.

Python with pandas

import glob
import pandas as pd

frames = [pd.read_csv(p, sep=None, engine="python", dtype=str).assign(source_file=p)
          for p in sorted(glob.glob("exports/*.csv"))]
merged = pd.concat(frames, ignore_index=True).drop_duplicates()
merged.to_csv("merged.csv", index=False)

pd.concat aligns columns by name and fills gaps with empty values, sep=None sniffs the delimiter per file, and dtype=str protects codes like 00123. Header names are matched exactly, so rename columns first if their case differs.

Tips and pitfalls

Duplicates that are not quite identical

Duplicate removal compares whole rows. Two rows for the same customer with a different plan value are both kept. If you need one row per email address, sort the merged file and deduplicate on that column in a spreadsheet or pandas (drop_duplicates(subset=["email"])). For single-column lists, Remove Duplicate Lines is quicker.

Watch the header spelling

E-mail, Email Address and email are different names to any tool. Check the Columns count after merging: if it is higher than you expect, a header is spelled differently in one file. Fix it in the source file and merge again.

Keep the source

The source_file column costs little and makes it easy to trace a bad row back to its export, or to filter one month out again later.

Next steps

Open the result as a workbook with CSV to Excel, load it into an API with CSV to JSON, or, if the merged file is now too big for an importer, cut it back into chunks with the CSV Splitter.

Frequently asked questions

Can I merge CSV files that have different columns?

Yes. When columns are matched by header name, the result contains every column from every file, and cells are left empty where a file had no such column.

Does the order of columns in each file matter?

Not when merging by header name. Each value is placed under its matching header regardless of position.

Can I merge files that use different delimiters?

Yes. The CSV Merger detects the delimiter of each file separately, so a semicolon file and a comma file can be combined, and you choose the output delimiter.

How are duplicate rows detected?

A row is removed only if every value matches a row already in the result. Rows that differ in any column are kept.

How many files can I merge?

There is no fixed number. Files are processed in your browser, so the practical limit is your device's memory; large files are more comfortable on a laptop than a phone.

Try it now: CSV Merger

Loading tool…