Menu Item Totals Across Tickets
Problem
You are given two DataFrames. `dish` has columns `dish_id` and `dish_name`. `ticket` has columns `ticket_id`, `dish_id`, `pending`, `served`, `comped`, `voided`.
For every dish, return the total `pending`, `served`, `comped` and `voided` counts summed across all of its tickets. A dish that appears on no ticket must still be returned with zeros. Order the result by `dish_name`. Output columns: `dish_name`, `pending`, `served`, `comped`, `voided`.
Input data
Example rows — the live problem includes the full dataset.
| dish_id | dish_name |
|---|---|
| 1 | Falafel |
| 2 | Hummus |
| 3 | Shakshuka |
| ticket_id | dish_id | pending | served | comped | voided |
|---|---|---|---|---|---|
| 88 | 1 | 10 | 5 | 0 | 1 |
| 89 | 1 | 2 | 3 | 1 | 0 |
| 90 | 2 | 4 | 4 | 2 | 2 |
Expected output
Your answer should return 3 rows with the columns dish_name, pending, served, comped, voided.
Starter code (Pandas (Python))
import pandas as pd
def menu_item_totals(dish, ticket) -> pd.DataFrame:
# Your code here
return dishSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock