HomeGuidesHow to Merge Two CSV Files into One
Guide

How to Merge Two CSV Files into One

3 methods — Excel, Python, and command line

Merging CSV files means stacking them vertically (combining rows from two files with the same columns) or joining them horizontally (matching rows from two files by a shared key column). Here's how to do both.

Method 1: Using Python (pandas) — most flexible

Python handles both stacking (vertical merge) and joining (horizontal merge by key).

  1. 1Install pandas: pip install pandas
  2. 2Use the script below for your merge type.

python

import pandas as pd

# VERTICAL MERGE: stack two files with the same columns
df1 = pd.read_csv("file1.csv")
df2 = pd.read_csv("file2.csv")
merged = pd.concat([df1, df2], ignore_index=True)
merged.to_csv("merged.csv", index=False)

# HORIZONTAL MERGE (JOIN): match rows by a shared key column
# merged = pd.merge(df1, df2, on="id", how="left")
# merged.to_csv("merged.csv", index=False)

After a vertical merge, run Remove Duplicate Rows using Tabular to deduplicate any records that appeared in both files.

Method 2: Using Excel (for small files)

  1. 1Open the first CSV in Excel.
  2. 2Open the second CSV in a separate Excel window.
  3. 3Select all rows in the second file (except the header row), copy them.
  4. 4Paste at the bottom of the first file.
  5. 5Save as CSV via File > Save As.

For files with different column orders, use Excel's VLOOKUP or the Python merge approach instead of copy-paste, which will misalign data.

Method 3: Command line (Unix/macOS/Linux) — fastest for large files

  1. 1Open your terminal.
  2. 2Run the command below. It concatenates both files, keeping only one header row.

bash

# Stack two CSV files (same columns), keeping one header
head -1 file1.csv > merged.csv
tail -n +2 file1.csv >> merged.csv
tail -n +2 file2.csv >> merged.csv

This method is extremely fast for large files because it just concatenates text. However, it doesn't validate that the columns match — always check the output has the right structure.

Frequently asked questions

What's the difference between stacking and joining CSV files?

Stacking (vertical merge) combines two files with the same columns by appending one below the other — useful for combining monthly exports or regional files. Joining (horizontal merge) matches rows from two files by a shared key column, adding new columns — similar to a database JOIN or Excel VLOOKUP.

How do I merge CSV files with different column names?

Use Tabular's Rename Columns tool to standardize the headers in both files before merging. In pandas, use pd.concat([df1, df2], ignore_index=True) — it aligns columns by name, filling missing values with NaN where a column exists in one file but not the other.

How do I remove duplicates after merging two CSV files?

After merging, upload the combined file to Tabular's Remove Duplicate Rows tool and select the key column (e.g. email or ID) to deduplicate on.

Can I merge more than two CSV files at once?

Yes. In pandas: pd.concat([pd.read_csv(f) for f in ['file1.csv', 'file2.csv', 'file3.csv']], ignore_index=True). On the command line, just add more tail commands: tail -n +2 file3.csv >> merged.csv

Ready to try the fastest method?

Instantly remove duplicate rows from any CSV or spreadsheet. Keep your data clean and analysis-ready.

Remove Duplicates — free