AnalystPath

Chess Club Standings

PandasMediumMid level~10 min

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.

players
player_idplayer_name
1Knight
2Bishop
3Rook
games
white_idblack_idwhite_scoreblack_score
1231
2322
3104

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 players

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