Orders with no customer, via indicator
A pandas exercise from Pandasdrill. Solve it with a Python editor in your browser running real pandas, and it is checked the moment you submit.
The task
Find the orders whose `cust_id` does not appear in `customers`. Use a left merge with indicator=True and keep only the left-only rows. Return the columns `order_id`, `cust_id`, `product_id` and `qty`. Row labels do not matter.
What this exercise teaches
The indicator column records where each merged row came from. After a left merge, left_only marks orders that found no customer, which is the anti-join analysts reach for when reconciling two systems. An outer merge would also pull in customers with no orders, whose order fields are NaN.
A hint if you get stuck
indicator=True adds a `_merge` column with the values left_only, right_only or both.
Try it now, free, no account needed
The first 15 tasks on Pandasdrill are free. Open it on the practice page, solve it, and get instant feedback with a hint. A free account adds the worked solution; Pro adds timed mode and the certificate.
Open this exerciseMore exercises in Combining and reshaping
- Inner merge on a shared keyPro
- Left merge keeps every orderPro
- Merge on differently named keysPro
- Stack two tables with concatPro
- Merge twice, then aggregatePro
- Wide to long with meltPro
- Long to wide with pivotPro
- Columns into rows with stackPro
- Index level into columns with unstackPro
- Label the source with concat keysPro
- One row per tag with explodePro
- Compare two price lists with suffixesPro