Skip to article frontmatterSkip to article content

In this lession, we will practice working with multi-indexed dataframes and data visualization tools learned this week.

import pandas as pd
import seaborn as sns

Our Dataset!

Run the cell below to see the DataFrame you’ll be working with today.

scoreboard = pd.DataFrame({
    "Player": ["Arona", "Anaya", "Thrisha", "Arpan", "Sonoma", "Asmi", "Alyssa", "Laura", "Alexis",
               "Sheamin", "Kevin", "MarioKartLegend"],
    "FavoriteTrack": ["Bowser’s Castle", "Rainbow Road", "Toad Harbor", "Big Blue", "Cheese Land", 
 "Toad Harbor", "Mario Circuit", "Bowser's Castle", "Mario Circuit", 
 "Coconut Mall", "Mario Circuit", "Cheese Land"],
    "Coins": [9, 8, 8, 9, 9, 11, 9, 7, 9, 8, 9, 10],
    "Mushrooms": [2, 0, 3, 1, 2, 2, 0, 3, 3, 1, 2, 3],
    "TopSpeed": [150, 70, 60, 125, 30, 20, 80, 94, 10, 77, 23, 49],
    "Character": ["Monty Mole", "Yoshi", "Luigi", "Blue Toad", "Toadette", "Princess Peach", 
                  "Princess Daisy", "Waluigi", "King Boo", "Bowser", "Mario", "Wario"],
    "Drivetrain": ["Bike", "Car", "4 wheeler", "Car", "Stroller", "4 wheeler", "Car", "Bike", 
                   "Stroller", "4 wheeler", "Bike", "Bike"],
    "Playstyle": ["Aggressive", "Aggressive", "Resourceful", "Speedster", "Resourceful", "Resourceful",
                  "Balanced", "Aggressive", "Balanced", "Balanced", "Balanced", "Resourceful"]
})

scoreboard

Practice Problems

Find the Player with the most Coins.

# TODO: Who has the most coins?

Find the average TopSpeed for each Playstyle category.

# TODO: What's the average speed of Aggressive players?

Create both a line plot and a bar plot to visualize TopSpeed trends by Playstyle. Compare the effectiveness of each in identifying patterns or outliers.

# TODO: Visualize!

Hierarchical Indexing

What if we wanted to set the index of our DataFrame to be 2 columns? Set the indices to Drivetrain and FavoriteTrack and then find all the Bikers who like Bowser's Castle.

# TODO: Which Bikers like Bowser's?

Next, find how many Mushrooms and Coins the Bike drivers have.

# TODO: How many Mushrooms and Coins do Bikers have?

Next, find the Player with the most Coins out of all Bike drivers.

# TODO: Which Biker has the most coins?