AnalystPath

Longest Support Sessions per Channel

PandasMediumMid level~10 min

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.

agents
agent_idgiven_namesurname
1LiamCarter
2NoraPatel
3OwenReyes
4PriyaWong
5QuinnDiaz
sessions
agent_idchannelseconds_long
1chat120
1voice180
2chat300
2voice240
3chat150

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 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