Analyze sales with groupby
UberMachine Learning Engineer · Technical ScreenLast updated
This question evaluates proficiency in data manipulation and analytics using pandas, specifically the ability to join relational tables and apply groupby aggregations to compute business metrics like total sales, average sales per order, and completion rates.
You are given three pandas DataFrames representing a food delivery marketplace:
orders(order_id, product_id, quantity, unit_price, status)products(product_id, category_id)categories(category_id, category_name)
Write code to join the tables and compute category-level business metrics using groupby and aggregation functions.
For each category_name, return:
total_sales: the sum ofquantity * unit_priceaverage_sales_per_order: the mean sales amount per order linecompletion_rate: the fraction of rows wherestatus == "completed"
The result should be a DataFrame with one row per category.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.