Skip to content

Instantly share code, notes, and snippets.

View MemphisMeng's full-sized avatar
💯

Anzhe Meng MemphisMeng

💯
  • Pittsburgh, PA
  • 00:23 (UTC -04:00)
View GitHub Profile
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
# 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)
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',
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
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
"""