
Items and aisles per order
easyItems and aisles per order
Instacart Pandas Interview Question
Instacart shoppers plan their route through a store around how many items an order has and how many aisles they need to visit.
Using the items DataFrame, find each order_id, the total number of items in that order as total_items, and the number of different aisles it covers as aisles. Assign the answer to result.
Asked of
- Data Analyst
- Product Analyst
- Business Analyst
- Analytics Engineer
- Data Scientist
itemsDataFrame22 rows
| Column Name | Type |
|---|---|
| order_id | int64 |
| product_name | str |
| aisle | str |
| quantity | int64 |
| unit_price | float64 |
itemsExample Input
| order_id | product_name | aisle | quantity | unit_price |
|---|---|---|---|---|
| 5001 | Bananas | Produce | 6 | 0.25 |
| 5001 | Oat Milk | Dairy | 2 | 4.49 |
| 5001 | Spinach | Produce | 1 | 3.99 |
| 5002 | Sourdough Bread | Bakery | 1 | 5.5 |
| 5002 | Eggs | Dairy | 1 | 3.29 |
| 5003 | Apples | Produce | 8 | 0.6 |
| 5003 | Greek Yogurt | Dairy | 4 | 1.25 |
| 5003 | Bagels | Bakery | 6 | 0.9 |
| 5003 | Cheddar Cheese | Dairy | 1 | 6.75 |
Example Output
| order_id | total_items | aisles |
|---|---|---|
| 5001 | 9 | 2 |
| 5002 | 2 | 2 |
| 5003 | 19 | 3 |
Explanation
Order 5001 has 6 bananas, 2 oat milks and 1 bag of spinach, which is 9 items from 2 aisles, Produce and Dairy. Order 5003 has 19 items from 3 aisles, because the yogurt and the cheese both come from Dairy and that aisle only counts once.
The example above is a small slice of the data. Your code runs against the full DataFrames.
- Aggregations
Similar questions
Company
Instacart
Difficulty
easy
Topic
Pandas
Your code
Loading Python in the background. You can start writing.