# Python Pandas For Your Grandpa - 2.13 Challenge: Fair Teams

Contents

## Setup

You’re organizing a competitive rock-skipping league. 6 coaches and 20 players have signed up. Your job is to randomly and fairly determine the teams, assigning players to coaches. Keep in mind that some teams will have three players and some teams will have four players. Given a Series of `coaches` and a Series of `players`, create a Series of random coach-to-player mappings. The resulting Series should have coach names in its index and corresponding player names in its values.

``````import numpy as np
import pandas as pd

coaches = pd.Series(['Aaron', 'Donald', 'Joshua', 'Peter', 'Scott', 'Stephen'], dtype='string')
print(coaches)
## 0      Aaron
## 1     Donald
## 2     Joshua
## 3      Peter
## 4      Scott
## 5    Stephen
## dtype: string
players = pd.Series(['Asher', 'Connor', 'Elizabeth', 'Emily', 'Ethan', 'Hannah', 'Isabella', 'Isaiah', 'James',
'Joshua', 'Julian', 'Layla', 'Leo', 'Madison', 'Mia', 'Oliver', 'Ryan', 'Scarlett', 'William',
'Wyatt'], dtype='string')
print(players)
## 0         Asher
## 1        Connor
## 2     Elizabeth
## 3         Emily
## 4         Ethan
## 5        Hannah
## 6      Isabella
## 7        Isaiah
## 8         James
## 9        Joshua
## 10       Julian
## 11        Layla
## 12          Leo
## 14          Mia
## 15       Oliver
## 16         Ryan
## 17     Scarlett
## 18      William
## 19        Wyatt
## dtype: string
``````

## Solution

``````coaches = coaches.sample(frac=1, random_state=2357)
players = players.sample(frac=1, random_state=7532)
repeats = np.ceil(len(players)/len(coaches)).astype('int64')
result = players.copy()
result.index = pd.Index(coaches_repeated, name='coach')
print(result)
## coach
## Stephen       Julian
## Scott         Joshua
## Aaron      Elizabeth
## Joshua         Asher
## Peter         Oliver
## Donald       William
## Stephen        Wyatt
## Scott         Isaiah
## Aaron          Ethan
## Peter            Leo
## Donald          Ryan
## Stephen     Scarlett
## Scott            Mia
## Aaron         Connor
## Joshua         James
## Peter          Emily
## Donald        Hannah
## Stephen        Layla
## Scott       Isabella
## dtype: string
``````