liveBook · Manning

Left outer join

As explained in The Well-Grounded Data Analyst

A left join combines records from two datasets while retaining every record from the left dataset and matching records from the right dataset when available.

A left outer join enriches a primary dataset with matching fields from another dataset while retaining every row from the primary, or left, side. Where no match exists, the added fields remain missing. It is useful when purchase records must stay complete even though some customer IDs are absent from a CRM export. section 3.4.2

Enriching purchase customers from CRM

Merge extracted purchase customers with CRM records on customer_id using a left join. The resulting rows retain purchase-derived customer records, add CRM names, postcodes, and ages where available, and expose unmatched records through missing CRM columns. Inspect those missing values before copying CRM details into the consolidated customer fields. section 3.4.2

sales_and_crm_customers = sales_customers.merge(crm,
 on="customer_id", how="left", suffixes=("_sales", "_crm"))
print(len(sales_and_crm_customers))
sales_and_crm_customers.isnull().sum()

The merge specifies customer_id as the key, how="left" to preserve sales_customers rows, and descriptive suffixes for overlapping columns. section 3.4.2

Practical checks after joining include:

  • Count missing fields from the added dataset to estimate how many left-side records matched. section 3.4.2
  • Use explicit suffixes for shared column names, then select matched rows before replacing or retaining source values. section 3.4.2
  • Track source-presence flags so consolidated records still show whether CRM data was found. section 3.4.2

How The Well-Grounded Data Analyst covers it

How deep it goes
Works through a pandas merge, missing-value inspection, match filtering, field replacement, and source flags.
Examples
Uses purchase customers and a CRM export, finding roughly 7,000 matched purchase records among about 33,000 rows.
What you can do after
Apply it via pandas to preserve a base customer dataset while adding available matched fields.
How it connects
Connects data modeling with schema transformation, missing values, customer IDs, and data provenance flags.

Also explained in

Compare how 6 books explain left outer join →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Data Analyst. The section links point to the parts of the book it draws on.