Players Whose Coach Left the Roster
Problem
You are given one DataFrame `roster`:
| Column | Type |
|-----------|------|
| player_id | int |
| full_name | str |
| coach_id | int |
| stipend | int |
`player_id` is unique. Each row gives a player, their monthly stipend, and the `player_id` of their coach (a coach is also listed as a player). Some players have no coach (`coach_id` is NaN).
Return the `player_id` of every player whose stipend is strictly below `2000` **and** whose coach is no longer on the roster. A coach is no longer on the roster when their id does not appear as any `player_id`.
Order the result by `player_id` ascending.
Input data
Example rows — the live problem includes the full dataset.
| player_id | full_name | coach_id | stipend |
|---|---|---|---|
| 1 | Ana | 5000 | |
| 2 | Beto | 1 | 1500 |
| 3 | Cleo | 9 | 1200 |
| 4 | Dario | 9 | 2500 |
| 5 | Eli | 8 | 800 |
Expected output
Your answer should return 2 rows with the columns player_id.
Starter code (Pandas (Python))
import pandas as pd
def coach_left_the_roster(roster) -> pd.DataFrame:
# Your code here
return rosterSolve 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