AnalystPath

Valid Relay Teams Across Three Clubs

PandasEasyJunior level~10 min

Problem

A swim relay must field exactly one swimmer from each of three clubs. A line-up is valid only if no two of the three chosen swimmers share the same id **and** no two share the same name.\n\nEach of `clubnorth`, `clubeast`, `clubwest` has columns `swimmer_id` and `swimmer_name`.\n\nReturn every valid line-up as three columns `leg_north`, `leg_east`, `leg_west` holding the swimmer names. Rows may be in any order.

Input data

Example rows — the live problem includes the full dataset.

clubnorth
swimmer_idswimmer_name
1Mara
2Niko
clubeast
swimmer_idswimmer_name
3Otis
clubwest
swimmer_idswimmer_name
3Otis
2Pia
10Mara

Expected output

Your answer should return 2 rows with the columns leg_north, leg_east, leg_west.

Starter code (Pandas (Python))

import pandas as pd

def valid_relay_teams(clubnorth, clubeast, clubwest) -> pd.DataFrame:
    # Your code here
    return clubnorth

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