Katkat

Analyze sales with groupby

UberMachine Learning Engineer · Technical Screen

Last 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:

  1. total_sales: the sum of quantity * unit_price
  2. average_sales_per_order: the mean sales amount per order line
  3. completion_rate: the fraction of rows where status == "completed"

The result should be a DataFrame with one row per category.