Category Stats
Beginner Mode

Start your terminal to use beginner mode.

Objective

You are analyzing order data for an e-commerce platform that stores product information and order records in separate tables.

Task

Join the products DataFrame with the orders DataFrame on product_id, then group by product category to calculate two metrics: the average price of products ordered (avg_price) and the total number of orders (total_orders_count). The average price should reflect every individual order row, not just distinct products. Save your result as result_df.

File Path

  • Products: /home/interview/products.csv
  • Orders: /home/interview/orders.csv
  • Starter script: /home/interview/category_stats.py

Schema

products.csv

Column Type
product_id integer
category string
price float

orders.csv

Column Type
order_id integer
product_id integer
quantity integer

Expected output schema

Column Type
category string
avg_price float
total_orders_count integer

Example

Given this sample input:

products

product_id category price
1 Apparel 25.99
2 Apparel 35.99
3 Footwear 50.00

orders

order_id product_id quantity
101 1 2
102 1 1
103 2 3
104 3 1

The output would be:

category avg_price total_orders_count
Apparel 29.32 3
Footwear 50.00 1

Apparel has three order rows (two for product 1 at $25.99, one for product 2 at $35.99), so avg_price = (25.99 + 25.99 + 35.99) / 3 = 29.32. Footwear has one order for product 3 at $50.00.

Terminal requires a larger screen

Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.

Linux Terminal Environment

Write and execute your solution in the terminal below.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →