{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-10-22T17:10:35.953179Z","iopub.execute_input":"2021-10-22T17:10:35.953595Z","iopub.status.idle":"2021-10-22T17:10:36.694634Z","shell.execute_reply.started":"2021-10-22T17:10:35.953505Z","shell.execute_reply":"2021-10-22T17:10:36.693775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Game data: The games.csv contains the teams playing in each game. The key variable is gameId.\n\nPlay data: The plays.csv file contains play-level information from each game. The key variables are gameId and playId.\n\nPlayer data: The players.csv file contains player-level information from players that participated in any of the tracking data files. The key variable is nflId.\n\nTracking data: Files tracking[season].csv contain player tracking data from season [season]. The key variables are gameId, playId, and nflId.\n\nPFF Scouting data: The PFFScoutingData.csv file contains play-level scouting information for each game. The key variables are gameId and playId.","metadata":{}},{"cell_type":"code","source":"\nscoutingData = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/PFFScoutingData.csv')\n# tracking2018 = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/tracking2018.csv')\n# tracking2019 = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/tracking2019.csv')\n# tracking2020 = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/tracking2020.csv')","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:10:36.696314Z","iopub.execute_input":"2021-10-22T17:10:36.696649Z","iopub.status.idle":"2021-10-22T17:10:36.791758Z","shell.execute_reply.started":"2021-10-22T17:10:36.696615Z","shell.execute_reply":"2021-10-22T17:10:36.790477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nprint('The shape of dataset for Scouting :', scoutingData.shape)\n# print('The shape of dataset for 2018 Season :', tracking2018.shape)\n# print('The shape of dataset for 2019 Season :', tracking2019.shape)\n# print('The shape of dataset for 2020 Season :', tracking2020.shape)","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:10:36.794321Z","iopub.execute_input":"2021-10-22T17:10:36.794563Z","iopub.status.idle":"2021-10-22T17:10:36.801159Z","shell.execute_reply.started":"2021-10-22T17:10:36.794532Z","shell.execute_reply":"2021-10-22T17:10:36.800341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Processing and Exploring Player data","metadata":{}},{"cell_type":"code","source":"players = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/players.csv')\nprint('data loading complete...')\nprint('*'*50)\nprint('The shape of dataset for players :', players.shape)\nprint('*'*50)\ndisplay(players.head().T)\nprint('*'*50)\ndisplay(players.tail().T)\nprint('*'*50)\nprint('Unique values in player height :', players['height'].unique())\nprint('*'*50)\n\nheight = []\n\nfor i in players['height']:\n    i = i.split('-')\n    \n    if len(i) == 1:\n        height.append(int(i[0]))\n        \n    else:\n        height.append((int(i[0])*12) + int(i[1]))\n        \nplayers['height'] = height\n\nprint('Height in inches of all players :', players['height'].unique())\nprint('*'*50)\n\nprint('Total Number of Colleges : ', players['collegeName'].nunique())\nprint('*'*50)\nprint('Top 20 Colleges contributing to player pool : \\n', players['collegeName'].value_counts()[:20])\nprint('*'*50)\nplayers['Position'].value_counts()\n\n# Fixing the dates\nplayers['birthDate'] = pd.to_datetime(players.birthDate)\nplayers['birthDate'] = players['birthDate'].dt.strftime('%Y-%m-%d')\ndisplay(players.tail(10).T)\n\n# Extracting Birthyear\nplayers['birthYear'] = pd.DatetimeIndex(players['birthDate']).year","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:10:36.802402Z","iopub.execute_input":"2021-10-22T17:10:36.802743Z","iopub.status.idle":"2021-10-22T17:10:36.917787Z","shell.execute_reply.started":"2021-10-22T17:10:36.802694Z","shell.execute_reply":"2021-10-22T17:10:36.917211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"college = players.groupby('collegeName').size().sort_values(0, ascending = False).reset_index()\ncollege.columns = ['Name', 'Count']","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:10:36.919789Z","iopub.execute_input":"2021-10-22T17:10:36.920307Z","iopub.status.idle":"2021-10-22T17:10:36.927422Z","shell.execute_reply.started":"2021-10-22T17:10:36.920143Z","shell.execute_reply":"2021-10-22T17:10:36.926652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, axs = plt.subplots(3,2, figsize = (20,15))\n\nplt.subplots_adjust(left=0.1,bottom=0.5,right=0.9, top=2, wspace=0.4)\n\n\nsns.histplot(players['height'],  binwidth = 1, kde = True, ax = axs[0,0])\naxs[0,0].set_xlabel('Height(in inches)')\n\nsns.histplot(players['weight'],  binwidth = 1, kde = True, ax = axs[0,1])\naxs[0,1].set_xlabel('Weight(in pounds)')\n\nsns.histplot(players['birthYear'],  binwidth = 1, kde = True, ax = axs[1,0])\naxs[1,0].set_xlabel('Year of Birth')\n\nsns.barplot( x = 'Name', y = 'Count', data = college[:20],  ax = axs[1,1])\naxs[1,1].set_xlabel('Top 20 colleges')\naxs[1,1].set_xticklabels(college['Name'][:20], rotation = 50)\n\nsns.histplot(players['Position'],  binwidth = 1, kde = True, ax = axs[2,0])\naxs[2,0].set_xlabel('Field Position')\naxs[2,0].set_xticklabels(players['Position'], rotation = 50)","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:10:36.928749Z","iopub.execute_input":"2021-10-22T17:10:36.928973Z","iopub.status.idle":"2021-10-22T17:10:39.438333Z","shell.execute_reply.started":"2021-10-22T17:10:36.928945Z","shell.execute_reply":"2021-10-22T17:10:39.437637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Processing and Exploring Games data","metadata":{}},{"cell_type":"code","source":"games = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/games.csv')\nprint('The shape of dataset for games :', games.shape)","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:10:39.439761Z","iopub.execute_input":"2021-10-22T17:10:39.440234Z","iopub.status.idle":"2021-10-22T17:10:39.451002Z","shell.execute_reply.started":"2021-10-22T17:10:39.440176Z","shell.execute_reply":"2021-10-22T17:10:39.450124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games['gameDate'] = pd.to_datetime(games.gameDate)\ngames['gameDate'] = games['gameDate'].dt.strftime('%Y-%m-%d')\ngames['dayofweek'] = pd.to_datetime(games.gameDate).dt.dayofweek\ngames['gameMonth'] = pd.to_datetime(games.gameDate).dt.month\ndisplay(games.head().T)\ndisplay(games.tail().T)","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:10:39.452709Z","iopub.execute_input":"2021-10-22T17:10:39.452995Z","iopub.status.idle":"2021-10-22T17:10:39.489404Z","shell.execute_reply.started":"2021-10-22T17:10:39.452963Z","shell.execute_reply":"2021-10-22T17:10:39.488719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig , ax = plt.subplots(figsize = (10,10))\nsns.countplot(games['season'])\nfor p in ax.patches:\n    ax.annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.4, p.get_height()+0.5),ha='center', va='top', color='black', size=14)","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:10:39.490344Z","iopub.execute_input":"2021-10-22T17:10:39.491043Z","iopub.status.idle":"2021-10-22T17:10:39.71409Z","shell.execute_reply.started":"2021-10-22T17:10:39.491008Z","shell.execute_reply":"2021-10-22T17:10:39.713089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig , ax = plt.subplots(2,1, figsize = (20,20))\n\nsns.countplot(games['homeTeamAbbr'], ax = ax[0])\nax[0].set_xlabel('Teams Hosting')\nfor p in ax[0].patches:\n    ax[0].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.4, p.get_height()+0.5),ha='center', va='top', color='black', size=14)\n    \nsns.countplot(games['visitorTeamAbbr'], ax = ax[1])\nax[1].set_xlabel('Teams Visiting')\nfor p1 in ax[1].patches:\n    ax[1].annotate('{:.1f}'.format(p1.get_height()), (p1.get_x()+0.4, p1.get_height()+0.5),ha='center', va='top', color='black', size=14)\n","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:10:39.71555Z","iopub.execute_input":"2021-10-22T17:10:39.715823Z","iopub.status.idle":"2021-10-22T17:10:41.164781Z","shell.execute_reply.started":"2021-10-22T17:10:39.715793Z","shell.execute_reply":"2021-10-22T17:10:41.163881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig , ax = plt.subplots(3, 1, figsize = (20,20))\n\nfig.suptitle('Games on different days of the week')\n\nsns.countplot(x= 'dayofweek', data = games.loc[games['season'] == 2018], ax = ax[0])\nax[0].set_xlabel('Season 2018')\nax[0].set_xticklabels(['Monday','Thursday','Saturday','Sunday'])\nfor p in ax[0].patches:\n    ax[0].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.4, p.get_height()+9),ha='center', va='top',\\\n                   color='black', size=14)\n    \nsns.countplot(x= 'dayofweek', data = games.loc[games['season'] == 2019], ax = ax[1])\nax[1].set_xlabel('Season 2019')\nax[1].set_xticklabels(['Monday','Thursday','Saturday','Sunday'])\nfor p in ax[1].patches:\n    ax[1].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.4, p.get_height()+9),ha='center', va='top',\\\n                   color='black', size=14)\n    \nsns.countplot(x= 'dayofweek', data = games.loc[games['season'] == 2020], ax = ax[2])\nax[2].set_xlabel('Season 2020')\nax[2].set_xticklabels(['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'])\nfor p in ax[2].patches:\n    ax[2].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.4, p.get_height()+9),ha='center', va='top',\\\n                   color='black', size=14)","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:10:41.166353Z","iopub.execute_input":"2021-10-22T17:10:41.167441Z","iopub.status.idle":"2021-10-22T17:10:41.990687Z","shell.execute_reply.started":"2021-10-22T17:10:41.167388Z","shell.execute_reply":"2021-10-22T17:10:41.989423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig , ax = plt.subplots(3, 1, figsize = (20,20))\n\nfig.suptitle('Games on different months')\n\nsns.countplot(x= 'gameMonth', data = games.loc[games['season'] == 2018], ax = ax[0])\nax[0].set_xlabel('Season 2018')\nax[0].set_xticklabels(['September','October','November','December'])\nfor p in ax[0].patches:\n    ax[0].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.4, p.get_height()+3),ha='center', va='top',\\\n                   color='black', size=14)\n    \nsns.countplot(x= 'gameMonth', data = games.loc[games['season'] == 2019], ax = ax[1])\nax[1].set_xlabel('Season 2019')\nax[1].set_xticklabels(['September','October','November','December'])\nfor p in ax[1].patches:\n    ax[1].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.4, p.get_height()+3),ha='center', va='top',\\\n                   color='black', size=14)\n    \nsns.countplot(x= 'gameMonth', data = games.loc[games['season'] == 2020], ax = ax[2])\nax[2].set_xlabel('Season 2020')\nax[2].set_xticklabels(['January','September','October','November','December'])\nfor p in ax[2].patches:\n    ax[2].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.4, p.get_height()+3),ha='center', va='top',\\\n                   color='black', size=14)","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:10:41.992018Z","iopub.execute_input":"2021-10-22T17:10:41.992549Z","iopub.status.idle":"2021-10-22T17:10:42.639412Z","shell.execute_reply.started":"2021-10-22T17:10:41.99251Z","shell.execute_reply":"2021-10-22T17:10:42.63881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig , ax = plt.subplots(figsize = (20,10))\n\nsns.countplot(games['week'])\nax.set_xlabel('Games per week of the season')\nfor p in ax.patches:\n    ax.annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.4, p.get_height()+1),ha='center', va='top',\\\n                   color='black', size=14)","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:10:42.640636Z","iopub.execute_input":"2021-10-22T17:10:42.641111Z","iopub.status.idle":"2021-10-22T17:10:43.075508Z","shell.execute_reply.started":"2021-10-22T17:10:42.641074Z","shell.execute_reply":"2021-10-22T17:10:43.074447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig , ax = plt.subplots(3, 1, figsize = (20,20))\n\nfig.suptitle('Games Timings during different seasons')\n\nsns.countplot(x= 'gameTimeEastern', data = games.loc[games['season'] == 2018], ax = ax[0])\nax[0].set_xlabel('Season 2018')\nfor p in ax[0].patches:\n    ax[0].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.4, p.get_height()+5),ha='center', va='top',\\\n                   color='black', size=14)\n    \nsns.countplot(x= 'gameTimeEastern', data = games.loc[games['season'] == 2019], ax = ax[1])\nax[1].set_xlabel('Season 2019')\nfor p in ax[1].patches:\n    ax[1].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.4, p.get_height()+5),ha='center', va='top',\\\n                   color='black', size=14)\n    \nsns.countplot(x= 'gameTimeEastern', data = games.loc[games['season'] == 2020], ax = ax[2])\nax[2].set_xlabel('Season 2020')\nfor p in ax[2].patches:\n    ax[2].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.4, p.get_height()+5),ha='center', va='top',\\\n                   color='black', size=14)","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:10:43.078058Z","iopub.execute_input":"2021-10-22T17:10:43.078389Z","iopub.status.idle":"2021-10-22T17:10:44.126407Z","shell.execute_reply.started":"2021-10-22T17:10:43.078353Z","shell.execute_reply":"2021-10-22T17:10:44.125526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Processing Games and Exploring plays data","metadata":{}},{"cell_type":"code","source":"plays = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/plays.csv')\nprint('The shape of dataset for plays :', plays.shape)","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:10:44.12775Z","iopub.execute_input":"2021-10-22T17:10:44.128036Z","iopub.status.idle":"2021-10-22T17:10:44.235739Z","shell.execute_reply.started":"2021-10-22T17:10:44.128004Z","shell.execute_reply":"2021-10-22T17:10:44.235155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#merge data with games data to extract more information\nplays = plays.merge(games, on = 'gameId')","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:10:44.236841Z","iopub.execute_input":"2021-10-22T17:10:44.237046Z","iopub.status.idle":"2021-10-22T17:10:44.265954Z","shell.execute_reply.started":"2021-10-22T17:10:44.237019Z","shell.execute_reply":"2021-10-22T17:10:44.265261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"homeTeam = []\nfor i,j in zip(plays['homeTeamAbbr'], plays['possessionTeam']):\n    if i == j:\n        homeTeam.append(1)\n    else:\n        homeTeam.append(0)\n    \nplays['HomeTeamPossesion'] = homeTeam\nplays.head().T","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:10:44.266956Z","iopub.execute_input":"2021-10-22T17:10:44.267785Z","iopub.status.idle":"2021-10-22T17:10:44.312107Z","shell.execute_reply.started":"2021-10-22T17:10:44.267748Z","shell.execute_reply":"2021-10-22T17:10:44.311252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig , ax = plt.subplots(3, 1, figsize = (20,20))\n\nfig.suptitle('Number of plays per Quater')\n\nsns.countplot(x= 'quarter', data = plays.loc[plays['season'] == 2018], ax = ax[0])\nax[0].set_xlabel('Season 2018')\n# ax[0].set_xticklabels(['September','October','November','December'])\nfor p in ax[0].patches:\n    ax[0].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.4, p.get_height()+10),ha='center', va='top',\\\n                   color='black', size=14)\n    \nsns.countplot(x= 'quarter', data = plays.loc[plays['season'] == 2019], ax = ax[1])\nax[1].set_xlabel('Season 2019')\n# ax[1].set_xticklabels(['September','October','November','December'])\nfor p in ax[1].patches:\n    ax[1].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.4, p.get_height()+10),ha='center', va='top',\\\n                   color='black', size=14)\n    \nsns.countplot(x= 'quarter', data = plays.loc[plays['season'] == 2020], ax = ax[2])\nax[2].set_xlabel('Season 2020')\n# ax[2].set_xticklabels(['January','September','October','November','December'])\nfor p in ax[2].patches:\n    ax[2].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.4, p.get_height()+10),ha='center', va='top',\\\n                   color='black', size=14)","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:11:30.151014Z","iopub.execute_input":"2021-10-22T17:11:30.151388Z","iopub.status.idle":"2021-10-22T17:11:30.8129Z","shell.execute_reply.started":"2021-10-22T17:11:30.151347Z","shell.execute_reply":"2021-10-22T17:11:30.812086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig , ax = plt.subplots(figsize = (20,10))\n\nsns.countplot(y = plays['possessionTeam'], order = plays['possessionTeam'].value_counts().index)\nax.set_xlabel('Number of plays')\nax.set_ylabel('Team in Possession')\n# for p in ax.patches:\n#     ax.annotate('{:.1f}'.format(p.get_x()), (p.get_height()+1, p.get_x()+0.4),\\\n#                    color='black', size=14)\n\n","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:44:29.427851Z","iopub.execute_input":"2021-10-22T17:44:29.428239Z","iopub.status.idle":"2021-10-22T17:44:29.942628Z","shell.execute_reply.started":"2021-10-22T17:44:29.428197Z","shell.execute_reply":"2021-10-22T17:44:29.941711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig , ax = plt.subplots(3, 1, figsize = (25,20))\n\nfig.suptitle('Plays made by teams per season')\n\nsns.countplot(x= 'possessionTeam', data = plays.loc[plays['season'] == 2018],ax = ax[0])\nax[0].set_xlabel('Season 2018')\n# ax[0].set_xticklabels(['September','October','November','December'])\nfor p in ax[0].patches:\n    ax[0].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.25, p.get_height()+8),ha='center', va='top',\\\n                   color='black', size=14)\n    \nsns.countplot(x= 'possessionTeam', data = plays.loc[plays['season'] == 2019], ax = ax[1])\nax[1].set_xlabel('Season 2019')\n# ax[1].set_xticklabels(['September','October','November','December'])\nfor p in ax[1].patches:\n    ax[1].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.25, p.get_height()+8),ha='center', va='top',\\\n                   color='black', size=14)\n    \nsns.countplot(x= 'possessionTeam', data = plays.loc[plays['season'] == 2020], ax = ax[2])\nax[2].set_xlabel('Season 2020')\n# ax[2].set_xticklabels(['January','September','October','November','December'])\nfor p in ax[2].patches:\n    ax[2].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.25, p.get_height()+8),ha='center', va='top',\\\n                   color='black', size=14)","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:36:00.001946Z","iopub.execute_input":"2021-10-22T17:36:00.002357Z","iopub.status.idle":"2021-10-22T17:36:02.223546Z","shell.execute_reply.started":"2021-10-22T17:36:00.002311Z","shell.execute_reply":"2021-10-22T17:36:02.22237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig , ax = plt.subplots(3, 1, figsize = (20,20))\n\nfig.suptitle('Number of plays per Quater')\n\nsns.countplot(x= 'quarter', data = plays.loc[plays['season'] == 2018], hue = 'HomeTeamPossesion',ax = ax[0])\nax[0].set_xlabel('Season 2018')\n# ax[0].set_xticklabels(['September','October','November','December'])\nfor p in ax[0].patches:\n    ax[0].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.2, p.get_height()+8),ha='center', va='top',\\\n                   color='black', size=14)\n    \nsns.countplot(x= 'quarter', data = plays.loc[plays['season'] == 2019], hue = 'HomeTeamPossesion', ax = ax[1])\nax[1].set_xlabel('Season 2019')\n# ax[1].set_xticklabels(['September','October','November','December'])\nfor p in ax[1].patches:\n    ax[1].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.2, p.get_height()+8),ha='center', va='top',\\\n                   color='black', size=14)\n    \nsns.countplot(x= 'quarter', data = plays.loc[plays['season'] == 2020], hue = 'HomeTeamPossesion', ax = ax[2])\nax[2].set_xlabel('Season 2020')\n# ax[2].set_xticklabels(['January','September','October','November','December'])\nfor p in ax[2].patches:\n    ax[2].annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.2, p.get_height()+8),ha='center', va='top',\\\n                   color='black', size=14)","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:13:50.604563Z","iopub.execute_input":"2021-10-22T17:13:50.604886Z","iopub.status.idle":"2021-10-22T17:13:51.656215Z","shell.execute_reply.started":"2021-10-22T17:13:50.604847Z","shell.execute_reply":"2021-10-22T17:13:51.655269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig , ax = plt.subplots(figsize = (20,10))\n# , order = plays['yardlineNumber'].value_counts().index\nsns.histplot( plays['yardlineNumber'], kde = True)\nax.set_xlabel('Number of plays')\nax.set_ylabel('Team in Possession')\nfor p in ax.patches:\n    ax.annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.5, p.get_height()+250),ha='center', va='top',\\\n                   color='black', size=14)\n","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:54:18.055585Z","iopub.execute_input":"2021-10-22T17:54:18.055941Z","iopub.status.idle":"2021-10-22T17:54:18.867718Z","shell.execute_reply.started":"2021-10-22T17:54:18.0559Z","shell.execute_reply":"2021-10-22T17:54:18.866659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plays['specialTeamsResult'].unique()","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:40:56.532458Z","iopub.execute_input":"2021-10-22T17:40:56.532961Z","iopub.status.idle":"2021-10-22T17:40:56.544669Z","shell.execute_reply.started":"2021-10-22T17:40:56.532895Z","shell.execute_reply":"2021-10-22T17:40:56.543313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig , ax = plt.subplots(figsize = (20,10))\n\nsns.countplot(x = plays['specialTeamsResult'], order = plays['specialTeamsResult'].value_counts().index)\nax.set_xlabel('Result of the play')\nax.set_ylabel('Count of Plays')\nax.set_xticklabels(['Touchback', 'Return', 'Kick Attempt Good', 'Fair Catch', 'Downed','Muffed', 'Kick Attempt No Good',\\\n                    'Out of Bounds','Non-Special Teams Result', 'Blocked Kick Attempt', 'Blocked Punt',\\\n                    'Kickoff Team Recovery'],rotation = 50)\nfor p in ax.patches:\n    ax.annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.4, p.get_height()+140),ha='center', va='top',\\\n                   color='black', size=14)\n","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:49:45.606513Z","iopub.execute_input":"2021-10-22T17:49:45.606847Z","iopub.status.idle":"2021-10-22T17:49:46.032981Z","shell.execute_reply.started":"2021-10-22T17:49:45.606815Z","shell.execute_reply":"2021-10-22T17:49:46.031888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig , ax = plt.subplots(figsize = (20,10))\n# , order = plays['yardlineNumber'].value_counts().index\nsns.histplot( plays['kickLength'], kde = True)\nax.set_xlabel('Distance of Kicks')\nax.set_ylabel('Count')\n# for p in ax.patches:\n#     ax.annotate('{:.1f}'.format(p.get_height()), (p.get_x()+0.5, p.get_height()+100),ha='center', va='top',\\\n#                    color='black', size=14)","metadata":{"execution":{"iopub.status.busy":"2021-10-22T17:58:51.836465Z","iopub.execute_input":"2021-10-22T17:58:51.837744Z","iopub.status.idle":"2021-10-22T17:58:52.355549Z","shell.execute_reply.started":"2021-10-22T17:58:51.837694Z","shell.execute_reply":"2021-10-22T17:58:52.354489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Total Number of Plays :', len(plays['passResult']))\nprint('*'*50)\nprint('Total Number of non pass plays :', plays['passResult'].isnull().sum())","metadata":{"execution":{"iopub.status.busy":"2021-10-22T18:03:34.640856Z","iopub.execute_input":"2021-10-22T18:03:34.641225Z","iopub.status.idle":"2021-10-22T18:03:34.652349Z","shell.execute_reply.started":"2021-10-22T18:03:34.641171Z","shell.execute_reply":"2021-10-22T18:03:34.651013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Processing 2018 Tracking data","metadata":{}},{"cell_type":"markdown","source":"- x : 0 to 120 (in yards)\n- y : 0 to 53.3 (in yards)\n- s : yards/sec\n- a : acc/sec^2\n- dis : Distance travelled from pervious point (in yards)\n- o : player Orientation (degree)\n- dir : Direction of movement (degree) ","metadata":{}},{"cell_type":"code","source":"# tracking2018 = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/tracking2018.csv')\n# print('The shape of dataset for 2018 Season :', tracking2018.shape)\n# print('*'*50)\n# tracking2018.head().T","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}