AnalystPath

Desk Cohesion Across Trading Sessions

PandasHardSenior level~10 min

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.

handoffs
from_brokerclockto_broker
109:152
211:453
311:501
410:301
213:003
desks
broker_iddesk_name
1Equities
2Equities
3Equities
4Bonds
5Bonds

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 handoffs

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