liveBook · Manning

Inner join

As explained in Pandas Workout: 200 exercises to make you a stronger data analyst

A join operation that retains only index or key values present in every input table.

An inner join combines tables while retaining only index values shared by every input. It is useful when mismatched dates would otherwise create missing values. section 11.14

Aligning time-series data

Oil prices were recorded daily, while ice-cream prices and miles traveled were recorded monthly. Joining all three with how='inner' keeps only their common dates, producing 275 index values from April 1986 through December 2021. The aligned frame can then support correlation analysis. section 11.14

df = (
    oil_df
    .join(ice_cream_df, how='inner')
    .join(miles_df, how='inner')
)

Use chained DataFrame.join calls with how='inner' to retain the intersection of all three indexes. section 11.14

How Pandas Workout: 200 exercises to make you a stronger data analyst covers it

How deep it goes
Defines index intersection, contrasts missing-value alternatives, and demonstrates chained joins without covering join internals.
Examples
Uses daily oil prices, monthly ice-cream prices, and monthly miles traveled.
What it assumes
Assumes familiarity with pandas DataFrames, indexes, and missing values.
What you can do after
Apply it via pandas DataFrame.join to create an aligned table for downstream analysis.
How it connects
Connects DataFrame.join with indexes, missing values, time series, and correlation.

Also explained in

Compare how 3 books explain inner join →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pandas Workout: 200 exercises to make you a stronger data analyst. The section links point to the parts of the book it draws on.