Itemize the Largest Repair Ticket
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.
| part_id | rate |
|---|---|
| 1 | 100 |
| 2 | 200 |
| ticket_id | part_id | qty |
|---|---|---|
| 1 | 1 | 2 |
| 3 | 2 | 1 |
| 2 | 2 | 3 |
| 2 | 1 | 4 |
| 4 | 1 | 10 |
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_linesSolve 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