Python
#31

Multiple Named Aggregations with groupby().agg() in Pandas

EasyAmazon
Interview Question #31
Asked at Amazon

Given an `orders_df` (department, order_id, customer_id, revenue), write a query to compute: total revenue (`total_rev`), average revenue (`avg_rev`), total orders (`order_count`), and unique customers (`unique_buyers`) per department.

Input Table: orders
3 rows preview
departmentorder_idcustomer_idrevenue
IT10115000
IT10227000
Sales10313000
Expected Output Structure2 rows
departmenttotal_revavg_revorder_countunique_buyers
IT12000600022
Sales3000300011
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.

Chat with us