AnalystPath

Agent Resolution Rate

PandasMediumMid level~10 min

Problem

A help desk tracks its support agents and the outcome of every ticket they handle.

You are given two DataFrames.

`agents` — one row per agent:

| Column | Type |
|----------|----------|
| agent_id | int |
| hired_at | datetime |

`agent_id` is unique. Each row records when an agent was hired.

`tickets` — one row per ticket:

| Column | Type |
|-----------|----------|
| agent_id | int |
| opened_at | datetime |
| outcome | text |

`(agent_id, opened_at)` is unique. `outcome` is either `'resolved'` or `'escalated'`.

An agent's **resolution rate** is the number of `'resolved'` tickets divided by the total number of tickets that agent handled. An agent who handled no tickets has a resolution rate of `0`. Round the rate to two decimal places.

Return a DataFrame with `agent_id` and `resolution_rate` for every agent, in any order.

Input data

Example rows — the live problem includes the full dataset.

agents
agent_idhired_at
32020-03-21 10:16:13
72020-01-04 13:57:59
22020-07-29 23:09:44
62020-12-09 10:39:37
tickets
agent_idopened_atoutcome
32021-01-06 03:30:46escalated
32021-07-14 14:00:00escalated
72021-06-12 11:57:29resolved
72021-06-13 12:58:28resolved
72021-06-14 13:59:27resolved

Expected output

Your answer should return 4 rows with the columns agent_id, resolution_rate.

Starter code (Pandas (Python))

import pandas as pd

def agent_resolution_rate(agents: pd.DataFrame, tickets: pd.DataFrame) -> pd.DataFrame:
    # Your code here
    return agents

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