Tickets That Eventually Closed
Problem
You are given two DataFrames. `accounts` has columns `account_id`, `company`, and `plan`. `ticket_events` has columns `event_id`, `account_id`, `logged_on`, and `status` (either `'open'` or `'resolved'`); each row is one status event.
Find every account whose ticket was opened and later resolved: there must be an `'open'` event followed by at least one `'resolved'` event on a strictly later date. Report the resolution time as the number of days between the first `'open'` event and the first `'resolved'` event that comes after it.
Return a DataFrame with columns `company` and `days_to_close`, ordered by `days_to_close` ascending, then `company` ascending.
Input data
Example rows — the live problem includes the full dataset.
| account_id | company | plan |
|---|---|---|
| 1 | Brightwave Labs | Pro |
| 2 | Olive & Co | Basic |
| 3 | Tundra Logistics | Enterprise |
| 4 | Maple Yard | Basic |
| 5 | Cobalt Systems | Pro |
| event_id | account_id | logged_on | status |
|---|---|---|---|
| 1 | 1 | 2024-03-04 | open |
| 2 | 1 | 2024-03-12 | resolved |
| 3 | 2 | 2024-03-01 | open |
| 4 | 2 | 2024-03-15 | resolved |
| 5 | 3 | 2024-03-10 | open |
Expected output
Your answer should return 3 rows with the columns company, days_to_close.
Starter code (Pandas (Python))
import pandas as pd
def tickets_that_eventually_closed(accounts, ticket_events) -> pd.DataFrame:
# Your code here
return accountsSolve 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