Skip to content
DataPackHub

Working with files

How to merge multiple CSV files

Combine several packs into one file safely: matching headers, keeping encodings consistent and removing duplicates afterwards.

After buying several SmartPacks you may want one combined file.

Before merging

  1. Check the headers match. Packs from the same dataset version share a column layout. Packs from different versions may not โ€” compare the first line of each file.
  2. Use one encoding. Our files are UTF-8. Mixing in files saved as Windows-1252 from other sources will corrupt accented characters.

Windows (PowerShell)

$files = Get-ChildItem .\UK-*.csv | Sort-Object Name
Get-Content $files[0] -TotalCount 1 | Set-Content merged.csv -Encoding utf8
foreach ($f in $files) { Get-Content $f | Select-Object -Skip 1 | Add-Content merged.csv -Encoding utf8 }

macOS / Linux

head -n 1 UK-0001.csv > merged.csv
for f in UK-*.csv; do tail -n +2 "$f" >> merged.csv; done

Python (pandas)

import glob, pandas as pd
frames = [pd.read_csv(f, dtype=str) for f in sorted(glob.glob("UK-*.csv"))]
pd.concat(frames, ignore_index=True).to_csv("merged.csv", index=False)

dtype=str keeps phone numbers and postcodes exactly as delivered.

After merging

Run a duplicate check on a normalised key (phone in E.164 or website domain) โ€” see how duplicates are measured. Then count the rows to confirm nothing was lost: the merged file should contain the sum of the individual row counts minus any duplicates you removed.

Updated 2026-09-26