Pandasdrill

Level 4: Combining and reshaping Exercise 47 of 63 Pro

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 exercise

More exercises in Combining and reshaping