The Problem
Real data moment
The real Chipotle orders table has an item_name on every row, but no separate reference for "what's this item's typical price" — that lives in a second table, built here as a real per-item average from the same data (standing in for a menu reference), covering 46 named menu items:
import pandas as pd
df = pd.read_csv("chipotle.tsv", sep="\t")
df["item_price"] = df["item_price"].str.replace("$", "", regex=False).astype(float)
excluded = {"Bowl", "Burrito", "Salad", "Crispy Tacos"} # generic, not real menu items
menu_items = sorted(set(df["item_name"].unique()) - excluded)
menu = df[df["item_name"].isin(menu_items)].groupby("item_name", as_index=False)["item_price"].mean()
menu = menu.rename(columns={"item_price": "typical_price"})
print(menu.shape)
(46, 2)
Two real tables, one shared column (item_name) — exactly the setup behind every real merge: order data in one table, reference data in another, needing to become one.
The gotcha
4,622 versus 4,610 — twelve rows are simply gone from the inner merge, with no error, no warning, nothing printed to suggest anything happened at all:
missing_items = set(df["item_name"].unique()) - set(merged["item_name"].unique())
print(missing_items)
{'Crispy Tacos', 'Burrito', 'Bowl', 'Salad'}
Those four generic item names (real, rare, ad-hoc order entries — 12 real rows total) never appeared in the menu reference table, so an inner merge dropped every one of them silently. Nothing about merged.shape alone would have revealed this — 4610 looks like a completely reasonable row count for a real dataset, unless it's specifically compared against the original.
This is Course 02's SQL join lesson, wearing pandas' clothes
An inner JOIN in SQL and an inner merge in pandas share the exact same silent-drop behavior, for the exact same reason: both only keep rows with a match on both sides, and neither raises anything when a row doesn't have one. The habit that catches this is identical either way — compare row counts before and after, every time, not just when something already looks wrong.
Table A has 100 rows. Table B has 80 rows, and 70 of Table A's key values also appear in Table B (the other 30 don't match anything in B). What's the row count of A.merge(B, on="key", how="left")?
A "left" merge guarantees every row from the left table (A) survives, matched or not — the 70 with a real match in B get B's columns filled in normally, and the 30 without a match still appear, with NaN in place of every column that would have come from B. The row count of a left merge is always exactly the left table's row count, regardless of how many rows actually matched.