Skip to content

Joining and Merging Datasets

Inner, left and outer joins, matching keys, and the classic mistakes — duplicated rows and silent data loss — to avoid.

Editorial team 2 min read

Combining datasets is essential, and one of the easiest places to introduce errors.

Types of Joins

  • Inner join: keep only rows with matching keys in both tables.
  • Left join: keep all rows from the left table, adding matches from the right where they exist.
  • Right join: the reverse.
  • Full outer join: keep all rows from both, matched where possible.

Choose Keys Carefully

Join on stable, unique identifiers. Names, descriptions and free-text fields make poor keys because of spelling and formatting differences.

Check Key Uniqueness

If a key appears multiple times in both tables, a join multiplies rows. One customer with three addresses joined to three orders produces nine rows. Check uniqueness before joining, and state the expected relationship (one-to-one, one-to-many).

merged = orders.merge(customers, on="customer_id", how="left", validate="many_to_one")

Check for Lost Rows

After an inner join, count rows before and after. Unmatched keys disappear silently. Use an indicator of match status to see what didn't join and why.

Standardise Keys First

Trim whitespace, align case, fix leading zeros and match types (a numeric ID in one table and text in the other won't match).

Time-Aware Joins

When joining events to reference data that changes over time — prices, customer segments — join to the version valid at the event's time, not the current version.

Verify Results

Check row counts, totals and a few records by hand after every important join.

More in Data for AI

All Data for AI guides →
Data for AI Guide · 1 min

How to Read a Dataset Card

The questions a dataset card should answer — what one row is, where the data came from, its licence and its quirks — before you use it.

Data for AI 1 min read 5 Apr 2026

Data for AI Guide · 2 min

Data Quality Dimensions

Accuracy, completeness, consistency, timeliness, validity and uniqueness: a framework for checking whether data is fit for purpose.

Data for AI 2 min read 4 Apr 2026

Data for AI Guide · 2 min

Handling Missing Data

Why data goes missing, how to find out, and the options — dropping, imputing, flagging — with their trade-offs.

Data for AI 2 min read 3 Apr 2026

Data for AI Guide · 2 min

Detecting and Handling Outliers

How to spot unusual values, decide whether they are errors or genuine extremes, and treat them appropriately.

Data for AI 2 min read 2 Apr 2026