Flip the Winning Side
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_id | event | winner_side | moves |
|---|---|---|---|
| 1 | Round A | w | 41 |
| 2 | Round A | b | 28 |
| 3 | Round B | w | 55 |
| 4 | Round B | b | 33 |
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_matchSolve 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