Merge Multiple CSV Files: Complete Guide
Last updated: March 2026 • 6 min read
Need to combine data from multiple CSV files? This guide covers every scenario from simple stacking to complex joins with different column structures.
Types of CSV Merges
1. Vertical Stack (Append)
Add rows from one file below another. Files should have the same columns.
2. Horizontal Join
Combine columns from different files based on a common key (like VLOOKUP).
Method 1: Command Line (Fast)
# Stack files (skip headers except first file) head -1 file1.csv > merged.csv tail -n +2 -q *.csv >> merged.csv # Or simpler if headers are identical cat *.csv > merged.csv
Method 2: Python Pandas
import pandas as pd
import glob
# Stack all CSVs in a folder
files = glob.glob('data/*.csv')
df = pd.concat([pd.read_csv(f) for f in files])
df.to_csv('merged.csv', index=False)
# Join on a key column
df1 = pd.read_csv('customers.csv')
df2 = pd.read_csv('orders.csv')
merged = pd.merge(df1, df2, on='customer_id', how='left')
merged.to_csv('customer_orders.csv', index=False)Method 3: Excel Power Query
- Data → Get Data → From File → From Folder
- Select folder containing CSVs
- Click "Combine & Transform"
- Power Query will stack all files automatically
Handling Mismatched Columns
When files have different columns:
# Pandas handles this automatically
df = pd.concat([pd.read_csv(f) for f in files],
ignore_index=True,
sort=False)
# Missing columns become NaNMerge Files Easily
Upload multiple CSVs to CleanCSV and combine them with smart column matching.
Try CleanCSV Free →