AnalystPath

Match Counts Between Chess Players

PandasMediumMid level~10 min

Problem

You are given a DataFrame `match_log` with columns `white_id`, `black_id` and `moves`. Each row is one chess game; the same two players may meet again with the colours swapped.

Treat a game between two players as the same pairing regardless of who played white. For every unordered pair of players, return the number of games they played and the total number of moves across those games. Use `player_a` for the smaller id and `player_b` for the larger id. Output columns: `player_a`, `player_b`, `matches`, `total_moves`.

Input data

Example rows — the live problem includes the full dataset.

match_log
white_idblack_idmoves
1230
2140
1325
3250

Expected output

Your answer should return 3 rows with the columns player_a, player_b, matches, total_moves.

Starter code (Pandas (Python))

import pandas as pd

def match_counts_between_players(match_log) -> pd.DataFrame:
    # Your code here
    return match_log

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