Longest Support Sessions per Channel
Problem
You are given two DataFrames. `agents` (CSV `agents.csv`) has columns agent_id, given_name, and surname; `sessions` (CSV `sessions.csv`) has columns agent_id, channel (either `chat` or `voice`), and seconds_long (the session length in seconds). For each channel, find the three longest sessions. If two sessions tie on length they share a rank and both are kept (so a channel may return more than three rows when there are ties at the cutoff). Output columns: the agent's `given_name`, the `channel`, and the duration as `clock` formatted HH:MM:SS. Order by `channel`, then by duration descending, then by `given_name` descending for ties.
Input data
Example rows — the live problem includes the full dataset.
| agent_id | given_name | surname |
|---|---|---|
| 1 | Liam | Carter |
| 2 | Nora | Patel |
| 3 | Owen | Reyes |
| 4 | Priya | Wong |
| 5 | Quinn | Diaz |
| agent_id | channel | seconds_long |
|---|---|---|
| 1 | chat | 120 |
| 1 | voice | 180 |
| 2 | chat | 300 |
| 2 | voice | 240 |
| 3 | chat | 150 |
Expected output
Your answer should return 6 rows with the columns given_name, channel, clock.
Starter code (Pandas (Python))
import pandas as pd
def longest_support_sessions_per_channel(agents, sessions) -> pd.DataFrame:
# Your code here
return agentsSolve 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