Skip to article frontmatterSkip to article content

In this lession, we will practice using groupby and data visualization tools learned this week.

import pandas as pd
import seaborn as sns
sns.set_theme()

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

scoreboard = pd.DataFrame({
    "Player": ["Arona", "Hannah", "Renusree", "Arpan", "Mia", "Asmi", "Alyssa", "Vani", "Vatsal",
               "Jasmine", "Kevin", "Alessia"],
    "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, 10, 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
# TODO: Who has the most coins per Drivetrain group?

Count how many Players in each Playstyle category like each FavoriteTrack.

# TODO: Which Playstyle likes Cheese Land the most?

Create both a line plot and a scatter plot to visualize TopSpeed trends by Playstyle.

# TODO: Visualize!

Compare the effectiveness of each in identifying patterns or outliers.

Given the data that is being plotted, what type of visualization would be most appropriate?

Create an alternative plot based on this consideration. Additionally, how could we visualize the Playstyle by Drivetrain?

# TODO: Visualize!

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?

Write a function players_above_average that calculates the average Coins for each Playstyle , then lists the Players whose Coins are above the average of the inputted Playstyle .

# Run this cell once before writing your function!
scoreboard.reset_index(inplace=True)
# TODO: Identify standout TAs!

def players_above_average(data, playstyle):
    """
    """
    ...


players_above_average(scoreboard, "Resourceful")