AnalystPath

Mid-Chain Mentors

PandasMediumMid level~10 min

Problem

A `Mentorship` DataFrame records direct mentor → mentee links as `mentor` and `mentee`. A *mid-chain mentor* is someone who mentors at least one person and is also themselves mentored by someone else (they sit in the middle of a chain, not at the top).

Report every mid-chain mentor and how many distinct mentees they have, in columns `mentor` and `mentee_count`, ordered by `mentor`.

Input data

Example rows — the live problem includes the full dataset.

mentorship
mentormentee
PriyaMarco
MarcoSven
MarcoTariq
TariqWendy

Expected output

Your answer should return 2 rows with the columns mentor, mentee_count.

Starter code (Pandas (Python))

import pandas as pd

def mid_chain_mentors(mentorship: pd.DataFrame) -> pd.DataFrame:
    # Your code here
    return mentorship

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