AnalystPath

Itemize the Largest Repair Ticket

PandasHardSenior level~10 min

Problem

You are given two DataFrames. `parts` has columns `part_id` and `rate`. `ticket_lines` has columns `ticket_id`, `part_id`, and `qty`. The cost of a line is `qty * rate`, and a ticket's total is the sum of its line costs. Find the ticket with the highest total cost; if several tickets tie, pick the one with the smallest `ticket_id`. Return its line items as a DataFrame with columns `part_id`, `qty`, and `line_cost`. Row order does not matter.

Input data

Example rows — the live problem includes the full dataset.

parts
part_idrate
1100
2200
ticket_lines
ticket_idpart_idqty
112
321
223
214
4110

Expected output

Your answer should return 2 rows with the columns part_id, qty, line_cost.

Starter code (Pandas (Python))

import pandas as pd

def largest_ticket(parts, ticket_lines) -> pd.DataFrame:
    # Your code here
    return ticket_lines

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