Desk Cohesion Across Trading Sessions
Problem
You are given two DataFrames. `desks` has columns `broker_id` and `desk_name` (which desk each broker sits on). `handoffs` has columns `from_broker`, `clock`, and `to_broker`, where `clock` is a string time of the form `HH:MM` recording one broker passing an order ticket to another.
The day splits into two sessions: the **morning** session is `00:00` through `12:00` (inclusive) and the **afternoon** session is `12:01` through `23:59`. For each desk and each session, compute a `cohesion_score`: add `+1` when the receiving broker is on the **same** desk as the sending broker, and `-1` when the ticket crosses to a **different** desk. The session and the score are attributed to the desk of the **sending** broker.
Return columns `desk_name`, `session_number` (1 for morning, 2 for afternoon), and `cohesion_score`, ordered by `desk_name` then `session_number`.
Input data
Example rows — the live problem includes the full dataset.
| from_broker | clock | to_broker |
|---|---|---|
| 1 | 09:15 | 2 |
| 2 | 11:45 | 3 |
| 3 | 11:50 | 1 |
| 4 | 10:30 | 1 |
| 2 | 13:00 | 3 |
| broker_id | desk_name |
|---|---|
| 1 | Equities |
| 2 | Equities |
| 3 | Equities |
| 4 | Bonds |
| 5 | Bonds |
Expected output
Your answer should return 4 rows with the columns desk_name, session_number, cohesion_score.
Starter code (Pandas (Python))
import pandas as pd
def desk_cohesion(handoffs, desks) -> pd.DataFrame:
# Your code here
return handoffsSolve 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