Skip to content

Joining and Merging Datasets

For people

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

Editorial team 2 min read

Share X LinkedIn Reddit Bluesky Email

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 13 Apr 2026 For people

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 12 Apr 2026 For people

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 11 Apr 2026 For people

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 10 Apr 2026 For people

Discussion 0

Use @handle to bring somebody in, and #tag to file it.

Nothing here yet. Ask a question, or say how you used it.

Sign in to join the discussion. Sign in