Python
All Top 50 Python & Pandas Interview Questions#34
Implement SQL HAVING Logic Using groupby().filter() in Pandas
MediumInterview Question #34
Given an `orders` DataFrame, keep only the rows belonging to customers whose average order value across all their purchases exceeds $500.
Input Table: orders
4 rows preview| order_id | customer_id | amount |
|---|---|---|
| 1 | 101 | 800 |
| 2 | 101 | 400 |
| 3 | 102 | 100 |
| 4 | 102 | 200 |
Expected Output Structure2 rows
| order_id | customer_id | amount |
|---|---|---|
| 1 | 101 | 800 |
| 2 | 101 | 400 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
Python 3.10 (Pandas)
Environment Ready
Click "Run & Test" to execute your Pandas code against the test assertions.