AnalystPath

Menu Item Totals Across Tickets

PandasEasyJunior level~10 min

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
dish_iddish_name
1Falafel
2Hummus
3Shakshuka
ticket
ticket_iddish_idpendingservedcompedvoided
88110501
8912310
9024422

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 dish

Solve 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

Related Pandas questions