24. Customers Without Orders
Difficulty: Medium · Topics: Joins, Filtering & Selection
You have two DataFrames: customers and orders.
Return the name of every customer who has never placed an order.
Row order does not matter; column names must match. Your code is graded on 3 test cases, including hidden edge cases.
Sample data
customers
| customer_id | name |
|---|---|
| 1 | Asha |
| 2 | Ben |
| 3 | Chitra |
| 4 | Dev |
orders
| order_id | customer_id | amount |
|---|---|---|
| 101 | 1 | 250 |
| 102 | 1 | 400 |
| 103 | 3 | 120 |
Expected output
| name |
|---|
| Ben |
| Dev |
Hints
Hint 1
Aleft_anti join keeps left rows that have no match on the right.Hint 2
Join on the shared key:customers.join(orders, "customer_id", "left_anti").Hint 3
Alternative: left join, then filter rows where an orders columnisNull().Learn the concepts
- left_semi / left_anti · 4 min read. Keep the rows that have a match, or the rows that do not, without duplicating anything.
- join · 5 min read. Combine DataFrames on a key: inner, left, right and full joins, and the duplicate-key fan-out trap.
- select · 6 min read. Choose, rename and compute columns, and why select beats a chain of withColumn calls.
PySpark functions you'll practise
- join
- left_anti
- select
Related problems
- Employees and Their Departments · Medium · Joins, Filtering & Selection
- Year-over-Year Growth · Medium · Joins, Filtering & Selection
- Employees Earning More than Their Manager · Medium · Joins, Filtering & Selection
- Joining on Nullable Keys · Medium · Joins, Null Handling, Filtering & Selection
- Order Lines with Product Details · Easy · Joins, Filtering & Selection
Browse
Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings · Data Lake · Lakehouse · Streaming · Data Prep for AI · Spark Performance
Difficulty: Easy · Medium · Hard · Learn · All problems · dbt practice