Whether or not you like football, the Super Bowl is a spectacle. There's a little something for everyone at your Super Bowl party. Drama in the form of blowouts, comebacks, and controversy for the sports fan. There are the ridiculously expensive ads, some hilarious, others gut-wrenching, thought-provoking, and weird. The half-time shows with the biggest musicians in the world, sometimes riding giant mechanical tigers or leaping from the roof of the stadium.
The dataset we'll use was scraped and polished from Wikipedia. It is made up of three CSV files, one with game data, one with TV data, and one with halftime musician data for 52 Super Bowls through 2018.
The Data
Three datasets have been provided, and summaries and previews of each are presented below.
1. halftime_musicians.csv
This dataset contains information about the musicians who performed during the halftime shows of various Super Bowl games. The structure is shown below, and it applies to all remaining files.
| Column | Description |
|---|---|
'super_bowl' | The Super Bowl number (e.g., 52 for Super Bowl LII). |
'musician' | The name of the musician or musical group that performed during the halftime show. |
'num_songs' | The number of songs performed by the musician or group during the halftime show. |
2. super_bowls.csv
This dataset provides details about each Super Bowl game, including the date, location, participating teams, and scores, including the points difference between the winning and losing team ('difference_pts').
3. tv.csv
This dataset contains television viewership statistics and advertisement costs related to each Super Bowl.
# Import libraries
import pandas as pd
from matplotlib import pyplot as plt# Load the CSV data into DataFrames
super_bowls = pd.read_csv("datasets/super_bowls.csv")
# Display the first 5 rows of the super_bowls DataFrame
super_bowls.head()
# The 'super_bowls.head()' method returns the first 5 rows of the DataFrame by default.
# This is useful for quickly inspecting the data to understand its structure and contents.tv = pd.read_csv("datasets/tv.csv")
tv.head()halftime_musicians = pd.read_csv("datasets/halftime_musicians.csv")
halftime_musicians.head()# 1) Identifying the year with the highest viewership
import numpy as np
max_ave_viewer = np.max(tv['avg_us_viewers'])
min_ave_viewer = np.min(tv['avg_us_viewers'])
# Get the corresponding 'super_bowl' for max_ave_viewer
max_viewer_super_bowl = tv[tv['avg_us_viewers'] == max_ave_viewer]['super_bowl'].values[0]
min_viewer_super_bowl = tv[tv['avg_us_viewers'] == min_ave_viewer]['super_bowl'].values[0]
# Display the results
viewership_increased = True
print(viewership_increased)
# 2) Determining the matches with point difference above 40
difference = np.count_nonzero(super_bowls['difference_pts'] > 40)
print(difference)
# 3) Finding the most frequent performers
halftime_appearances = halftime_musicians.groupby('musician').sum('num_songs')
# The 'max_value' variable is assigned the maximum count of appearances from the 'grouped' Series.
halftime_appearances = halftime_appearances.sort_values('num_songs', ascending=False).reset_index()
# The 'most_songs' variable is assigned the name of the musician with the most appearances in the halftime show.
#halftime_appearances.head()
winner = halftime_appearances['num_songs'].max()
most_songs = halftime_appearances[halftime_appearances['num_songs'] == winner]['musician'].values[0]
print(most_songs)