AnalystPath

Top Earning Dish per Diner

PandasMediumMid level~10 min

Problem

A restaurant tracks every order line and the menu price of each dish. The DataFrame `orders` (loaded from `orders.csv`) has `(order_id, dish_id, diner_id, servings)`, and the DataFrame `menu` (loaded from `menu.csv`) has `(dish_id, unit_price)`.

For each diner, report the dish on which they spent the most money in total (sum over all their order lines of servings multiplied by unit_price). If a diner's maximum spend is tied across several dishes, report every one of those dishes.

Return the columns `diner_id` and `dish_id`.

Input data

Example rows — the live problem includes the full dataset.

orders
order_iddish_iddiner_idservings
1110110
231017
311029
421026
5310210
menu
dish_idunit_price
110
225
315

Expected output

Your answer should return 4 rows with the columns diner_id, dish_id.

Starter code (Pandas (Python))

import pandas as pd

def top_earning_dish_per_diner(orders, menu) -> pd.DataFrame:
    # Your code here
    return orders

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