This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np # linear algebra | |
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) | |
import base64 | |
import os | |
import re | |
import math | |
from matplotlib.offsetbox import OffsetImage, AnnotationBbox | |
import matplotlib as mpl | |
import matplotlib.pyplot as plt | |
import matplotlib.patches as patches |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# data preparation | |
plays = pd.read_csv('../input/nfl-big-data-bowl-2021/plays.csv') | |
games = pd.read_csv('../input/nfl-big-data-bowl-2021/games.csv') | |
players = pd.read_csv('../input/nfl-big-data-bowl-2021/players.csv') | |
dataDir = "/kaggle/input/nfl-big-data-bowl-2021/" | |
weeks = pd.DataFrame(columns=['time', 'x', 'y', 's', 'a', 'dis', 'o', 'dir', 'event', 'nflId', | |
'displayName', 'jerseyNumber', 'position', 'frameId', 'team', 'gameId', | |
'playId', 'playDirection', 'route']) | |
for i in range(1,18): | |
weeks = pd.concat([weeks, pd.read_csv(dataDir+"week{}.csv".format(i))], ignore_index=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
measure = widgets.Dropdown( | |
options=['playResult', 'offensePlayResult', 'epa'], | |
value='playResult', | |
description='Measure', | |
) | |
week = widgets.Dropdown( | |
options=['Overall', 'Week 1', 'Week 2', 'Week 3', 'Week 4', 'Week 5', 'Week 6', 'Week 7', 'Week 8', | |
'Week 9', 'Week 10', 'Week 11', 'Week 12', 'Week 13', 'Week 14', 'Week 15', 'Week 16', 'Week 17'], | |
value='Overall', | |
description='Period', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def barit(week, measure): | |
""" | |
Filters and plot the dataframe as a bar plot of teams' defence performance | |
Args: | |
----- | |
* week (str): the period to filter on, or "Overall" to display the entire season | |
* measure (str): the option of measurement | |
Returns: | |
-------- | |
A matplotlib bar plot |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def scatterit(week): | |
""" | |
Filters and plot the dataframe as a scatter plot of teams' defence performance | |
Args: | |
----- | |
* week (str): the period to filter on, or "Overall" to display the entire season | |
Returns: | |
-------- | |
A matplotlib scatter plot | |
""" |
OlderNewer