AnalystPath

Flip the Winning Side

PandasEasyJunior level~10 min

Problem

You are given a DataFrame `chess_match` with columns `match_id`, `event`, `winner_side`, and `moves`. The `winner_side` column holds the single character `'w'` (white) or `'b'` (black).

Return every row with `winner_side` flipped: each `'w'` becomes `'b'` and each `'b'` becomes `'w'`. Keep all four columns and order the result by `match_id`.

Input data

Example rows — the live problem includes the full dataset.

chess_match
match_ideventwinner_sidemoves
1Round Aw41
2Round Ab28
3Round Bw55
4Round Bb33

Expected output

Your answer should return 4 rows with the columns match_id, event, winner_side, moves.

Starter code (Pandas (Python))

import pandas as pd

def flip_the_winning_side(chess_match) -> pd.DataFrame:
    # Your code here
    return chess_match

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