pythonnumpypandas
Ben Gorman

Ben Gorman

Life's a garden. Dig it.

You developed a multiplayer indie game called 🌹 Rose Thorn. Players compete in one of two venues - the ocean or the desert. You track the outcome of five games between three players in a DataFrame called games.

import numpy as np
import pandas as pd
 
games = pd.DataFrame({
    'bella1':   ['2nd', '3rd', '1st', '2nd', '3rd'],
    'billybob': ['1st', '2nd', '2nd', '1st', '2nd'],
    'nosoup4u': ['3rd', '1st', '3rd', '3rd', '3rd'],
    'venue': ['desert', 'ocean', 'desert', 'ocean', 'desert']
})
 
print(games)
#   bella1 billybob nosoup4u   venue
# 0    2nd      1st      3rd  desert
# 1    3rd      2nd      1st   ocean
# 2    1st      2nd      3rd  desert
# 3    2nd      1st      3rd   ocean
# 4    3rd      2nd      3rd  desert

Now you want to analyze the data. Convert the games DataFrame into a new DataFrame that identifies how many times each (player, placement) occurs per venue, specifically with venue as the row index and (player, placed) as the column MultiIndex.


Solution

This content is gated

Subscribe to one of the products below to gain access