Chess Club Standings
Problem
You are given two DataFrames. `players` has columns `player_id`, `player_name`. `games` has columns `white_id`, `black_id`, `white_score`, `black_score`; each row is one game (who played White, who played Black, and the rounds each side won).
Build the club standings. For each player report:
- `player_name`
- `games_played`
- `league_points`: Win = 3, Draw = 1, Loss = 0
- `rounds_for`: total rounds the player won
- `rounds_against`: total rounds the player conceded
- `rounds_diff`: `rounds_for` minus `rounds_against`
Return the columns in the order above, sorted by `league_points` DESC, then `rounds_diff` DESC, then `player_name` ASC.
Input data
Example rows — the live problem includes the full dataset.
| player_id | player_name |
|---|---|
| 1 | Knight |
| 2 | Bishop |
| 3 | Rook |
| white_id | black_id | white_score | black_score |
|---|---|---|---|
| 1 | 2 | 3 | 1 |
| 2 | 3 | 2 | 2 |
| 3 | 1 | 0 | 4 |
Expected output
Your answer should return 3 rows with the columns player_name, games_played, league_points, rounds_for, rounds_against, rounds_diff.
Starter code (Pandas (Python))
import pandas as pd
def chess_club_standings(players, games) -> pd.DataFrame:
# Your code here
return playersSolve 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