AnalystPath

Tickets That Eventually Closed

PandasMediumMid level~10 min

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.

accounts
account_idcompanyplan
1Brightwave LabsPro
2Olive & CoBasic
3Tundra LogisticsEnterprise
4Maple YardBasic
5Cobalt SystemsPro
ticket_events
event_idaccount_idlogged_onstatus
112024-03-04open
212024-03-12resolved
322024-03-01open
422024-03-15resolved
532024-03-10open

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 accounts

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