๐ Pandas Interview Question (Query-Based | Tricky)
Ques : You have a DataFrame df with columns customer_id, order_date, and amount.
How would you find customers who placed more than 3 orders AND whose total purchase amount is greater than 50,000?
โ
Answer
df.groupby('customer_id')
.agg(order_count=('order_date', 'count'),
total_amount=('amount', 'sum'))
.query('order_count > 3 and total_amount > 50000')
โ ๏ธ Why This Is Tricky
Candidates often apply filters before aggregation or struggle to combine multiple conditions correctly.
๐ก Interview Tip:
For conditions on aggregated values โ groupby โ agg โ query
๐ React if this helped
Post #2015
1.93K
- ๐ 5
- โค 2
- ๐ 1