Python
All Top Python 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: df
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
Starting the real Python + pandas runtime (one-time download)…