Customers with no orders

Pandas data engineering interview problem. Difficulty: beginner. Pattern: Merges. About 10 minutes. Free to practice.

Find customers that never appear in the orders table. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

Finding rows with no match in another table is a common check. Here you want the customers who have never placed an order. customers has customer_id and name. orders has order_id and customer_id. A customer can appear in many orders, and some order rows have a missing customer_id. Return the customers that have no order. The result has the columns customer_id and name, sorted by customer_id, with a clean index. The editor builds both tables and ends with result = customers. Change the last line to build your answer. You can use isin with ~, or a merge with an indicator.

Requirements

  • Find the customers whose customer_id does not appear in orders.
  • Return customer_id and name.
  • Sort by customer_id and reset the index.
  • Store the DataFrame in result.

Constraints

  • customers has 5 rows. orders has 5 rows, and one of them has a missing customer_id.
  • A customer who appears in many orders is still one customer with orders.
  • The missing customer_id in orders must not change the answer.

Examples

Input: customers customer_id | name 1 | Ann 2 | Bo 3 | Cy 4 | Di 5 | Eli orders order_id | customer_id 10 | 1 11 | 1 12 | 3 13 | NULL 14 | 3 Output: customer_id | name 2 | Bo 4 | Di 5 | Eli Customers 1 and 3 have orders. The missing id in orders matches nobody. Bo (2), Di (4) and Eli (5) have none.

Topics: lakebench, pandas, anti join, isin, merge.

More interview problems · All interview problems · Learn data engineering

beginner

Customers with no orders

Interview-style drill: Find customers that never appear in the orders table.

`customers` has `customer_id` and `name`. `orders` has `order_id` and `customer_id`; a customer can appear many times and some order rows have a missing `customer_id`. Return the customers that have no order, with columns `customer_id` and `name`, sorted by `customer_id` with a clean index. Assign the DataFrame to `result`.