{"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":"markdown","source":"<div class=\"alert alert-block alert-info\">  \n    <h3><strong>👨‍💻 Getting Started with NFL Big Data Bowl 2022.\nApplying analytical skills to evaluate team performance</strong></h3>\n    <i></i>\n</div>","metadata":{}},{"cell_type":"markdown","source":"# <center><img src=\"https://a.espncdn.com/photo/2021/0719/nfl_offensive-arsenal_16x9_608x342.jpg\"></center>","metadata":{}},{"cell_type":"markdown","source":"<div class=\"alert alert-block alert-info\">\n  <hr>\n<b>Source of Data: </b> \n<hr> \n <a href=\"https://www.kaggle.com/c/nfl-big-data-bowl-2022/data\">https://www.kaggle.com/c/nfl-big-data-bowl-2022/data</a>\n</div> ","metadata":{}},{"cell_type":"markdown","source":"<div class=\"alert alert-block alert-info\">  \n \n<hr>\n<b>Data Description: </b> \n<hr> \n    <p>We have 5 sets of data containing the stats of the player tracking, play, game, player, and PFF scouting data for all 2018-2020 Special Teams plays.The games.csv contains the teams playing in each game. The primary  keyis gameId.The plays.csv file contains play-level information from each game. The foreign key and the primary key are gameId and playId respectively.The players.csv file contains player-level information from players that participated in any of the tracking data files. The primary key is nflId.tracking[season].csv contain player tracking data from season [season]. The key variables are gameId, playId, and nflId.The PFFScoutingData.csv file contains play-level scouting information for each game. The key variables are gameId and playId.</p>\n <a href=\"https://www.kaggle.com/c/nfl-big-data-bowl-2022/data\">https://www.kaggle.com/c/nfl-big-data-bowl-2022/data</a>\n   \n</div>","metadata":{}},{"cell_type":"markdown","source":"<div class=\"alert alert-block alert-danger\">  \n<h2><center><strong>Importing Necessary Libraries 📚 📖 📕 📗 📘 📙</strong></center></h2>\n</div>","metadata":{}},{"cell_type":"code","source":"import numpy as np \nimport warnings\nwarnings.simplefilter(action='ignore', category=FutureWarning)\nimport pandas as pd\nimport seaborn as sns\nimport missingno as msno\nimport plotly.graph_objects as go\nimport plotly.offline as po\nfrom plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot\nimport matplotlib.pyplot as plt\nimport matplotlib.ticker as ticker\nimport plotly.express as px\nimport random\nimport plotly.figure_factory as ff \nfrom wordcloud import WordCloud\n","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:04:52.700903Z","iopub.execute_input":"2022-01-25T09:04:52.701589Z","iopub.status.idle":"2022-01-25T09:04:57.018307Z","shell.execute_reply.started":"2022-01-25T09:04:52.7015Z","shell.execute_reply":"2022-01-25T09:04:57.017496Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div class=\"alert alert-block alert-danger\">  \n<h2><center><strong>Data loading and exploration 📁 📂</strong></center></h2>\n        \n</div>","metadata":{"execution":{"iopub.status.busy":"2022-01-03T10:10:43.534767Z","iopub.execute_input":"2022-01-03T10:10:43.535443Z","iopub.status.idle":"2022-01-03T10:10:43.541588Z","shell.execute_reply.started":"2022-01-03T10:10:43.535402Z","shell.execute_reply":"2022-01-03T10:10:43.540388Z"}}},{"cell_type":"code","source":"players_df =pd.read_csv(\"/kaggle/input/nfl-big-data-bowl-2022/players.csv\")\npffScoutingData_df=pd.read_csv(\"/kaggle/input/nfl-big-data-bowl-2022/PFFScoutingData.csv\")\ngames_df=pd.read_csv(\"/kaggle/input/nfl-big-data-bowl-2022/games.csv\")\nplays_df=pd.read_csv(\"/kaggle/input/nfl-big-data-bowl-2022/plays.csv\")\ntracking18_df=pd.read_csv(\"/kaggle/input/nfl-big-data-bowl-2022/tracking2018.csv\")\ntracking19_df=pd.read_csv(\"/kaggle/input/nfl-big-data-bowl-2022/tracking2019.csv\")\ntracking20_df=pd.read_csv(\"/kaggle/input/nfl-big-data-bowl-2022/tracking2020.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:04:57.021101Z","iopub.execute_input":"2022-01-25T09:04:57.022015Z","iopub.status.idle":"2022-01-25T09:07:05.120218Z","shell.execute_reply.started":"2022-01-25T09:04:57.021972Z","shell.execute_reply":"2022-01-25T09:07:05.119368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Shape of the data files ( number of rows and number of columns) \nprint('\\033[1m'\"Shape of the Players File \"'\\033[0m',players_df.shape )\nprint('\\033[1m'\"Shape of the Scoutting file\"'\\033[0m', pffScoutingData_df.shape)\nprint('\\033[1m'\"Shape of the Games File\"'\\033[0m',games_df.shape)\nprint('\\033[1m'\"Shape of the plays File\"'\\033[0m',plays_df.shape)\nprint('\\033[1m'\"Shape of the tracking 2018 File\"'\\033[0m',tracking18_df.shape)\nprint('\\033[1m'\"Shape of the tracking 2019 File\"'\\033[0m',tracking19_df.shape)\nprint('\\033[1m'\"Shape of the tracking 2020 File\"'\\033[0m',tracking20_df.shape)","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:05.126125Z","iopub.execute_input":"2022-01-25T09:07:05.126966Z","iopub.status.idle":"2022-01-25T09:07:05.136785Z","shell.execute_reply.started":"2022-01-25T09:07:05.126922Z","shell.execute_reply":"2022-01-25T09:07:05.13598Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players_df.head(10).style.set_caption(\"Engagement Dataframe\").set_properties(**{'background-color': 'peachpuff',\n                           'color': 'midnightblue','border': '1.5px  solid black'})","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:05.16401Z","iopub.execute_input":"2022-01-25T09:07:05.164907Z","iopub.status.idle":"2022-01-25T09:07:05.290686Z","shell.execute_reply.started":"2022-01-25T09:07:05.164865Z","shell.execute_reply":"2022-01-25T09:07:05.289949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pffScoutingData_df.head(10).style.set_caption(\"Engagement Dataframe\").set_properties(**{'background-color': 'peachpuff',\n                           'color': 'midnightblue','border': '1.5px  solid black'})","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:05.292469Z","iopub.execute_input":"2022-01-25T09:07:05.293118Z","iopub.status.idle":"2022-01-25T09:07:05.347671Z","shell.execute_reply.started":"2022-01-25T09:07:05.293079Z","shell.execute_reply":"2022-01-25T09:07:05.34674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games_df.head(10).style.set_caption(\"Engagement Dataframe\").set_properties(**{'background-color': 'peachpuff',\n                           'color': 'midnightblue','border': '1.5px  solid black'})","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:05.349199Z","iopub.execute_input":"2022-01-25T09:07:05.349535Z","iopub.status.idle":"2022-01-25T09:07:05.376312Z","shell.execute_reply.started":"2022-01-25T09:07:05.349497Z","shell.execute_reply":"2022-01-25T09:07:05.375527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plays_df.head(10).style.set_caption(\"Engagement Dataframe\").set_properties(**{'background-color': 'peachpuff',\n                           'color': 'midnightblue','border': '1.5px  solid black'})","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:05.377837Z","iopub.execute_input":"2022-01-25T09:07:05.378852Z","iopub.status.idle":"2022-01-25T09:07:05.439644Z","shell.execute_reply.started":"2022-01-25T09:07:05.37881Z","shell.execute_reply":"2022-01-25T09:07:05.438867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tracking18_df.head(10).style.set_caption(\"Engagement Dataframe\").set_properties(**{'background-color': 'peachpuff',\n                           'color': 'midnightblue','border': '1.5px  solid black'})","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:05.441119Z","iopub.execute_input":"2022-01-25T09:07:05.442061Z","iopub.status.idle":"2022-01-25T09:07:05.490133Z","shell.execute_reply.started":"2022-01-25T09:07:05.442022Z","shell.execute_reply":"2022-01-25T09:07:05.489332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tracking19_df.head(10).style.set_caption(\"Engagement Dataframe\").set_properties(**{'background-color': 'peachpuff',\n                           'color': 'midnightblue','border': '1.5px  solid black'})","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:05.49174Z","iopub.execute_input":"2022-01-25T09:07:05.492647Z","iopub.status.idle":"2022-01-25T09:07:05.541835Z","shell.execute_reply.started":"2022-01-25T09:07:05.49261Z","shell.execute_reply":"2022-01-25T09:07:05.541039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tracking20_df.head(10).style.set_caption(\"Engagement Dataframe\").set_properties(**{'background-color': 'peachpuff',\n                           'color': 'midnightblue','border': '1.5px  solid black'})","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:05.543568Z","iopub.execute_input":"2022-01-25T09:07:05.544373Z","iopub.status.idle":"2022-01-25T09:07:05.594222Z","shell.execute_reply.started":"2022-01-25T09:07:05.544294Z","shell.execute_reply":"2022-01-25T09:07:05.593441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('\\033[1m'\"Data types of each column in players data file\\n\"'\\033[0m',players_df.dtypes)\nprint('\\033[1m'\"Data types of each column in Scouting data file\\n\"'\\033[0m',pffScoutingData_df.dtypes)\nprint('\\033[1m'\"Data types of each column in games data file\\n\"'\\033[0m',games_df.dtypes)\nprint('\\033[1m'\"Data types of each column in plays data file\\n\"'\\033[0m',plays_df.dtypes)\nprint('\\033[1m'\"Data types of each column in tracking 2018 data file\\n\"'\\033[0m',tracking18_df.dtypes)\nprint('\\033[1m'\"Data types of each column in tracking 2019 data file\\n\"'\\033[0m',tracking19_df.dtypes)\nprint('\\033[1m'\"Data types of each column in tracking 2020 data file\\n\"'\\033[0m',tracking20_df.dtypes)","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:05.59579Z","iopub.execute_input":"2022-01-25T09:07:05.596727Z","iopub.status.idle":"2022-01-25T09:07:05.61796Z","shell.execute_reply.started":"2022-01-25T09:07:05.596665Z","shell.execute_reply":"2022-01-25T09:07:05.617192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Missing Value check\nprint('\\033[1m'\"Missing value present in each column of players data file\\n\"'\\033[0m',players_df.isna().any())\nprint('\\033[1m'\"Missing value present in each column of Scouting data file\\n\"'\\033[0m',pffScoutingData_df.isna().any())\nprint('\\033[1m'\"Missing value present in each column of games data file\\n\"'\\033[0m',games_df.isna().any())\nprint('\\033[1m'\"Missing value present in each column of plays data file\\n\"'\\033[0m',plays_df.isna().any())\nprint('\\033[1m'\"Missing value present in each column of tracking 2018 data file\\n\"'\\033[0m',tracking18_df.isna().any())\nprint('\\033[1m'\"Missing value present in each column of tracking 2019 data file\\n\"'\\033[0m',tracking19_df.isna().any())\nprint('\\033[1m'\"Missing value present in each column of tracking 2020 data file\\n\"'\\033[0m',tracking20_df.isna().any())","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:05.619276Z","iopub.execute_input":"2022-01-25T09:07:05.619855Z","iopub.status.idle":"2022-01-25T09:07:28.919071Z","shell.execute_reply.started":"2022-01-25T09:07:05.619813Z","shell.execute_reply":"2022-01-25T09:07:28.918171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Missing Value check\nprint('\\033[1m'\"Missing value count in each column of players data file\\n\"'\\033[0m',players_df.isna().sum())\nprint('\\033[1m'\"Missing value count in each column of Scouting data file\\n\"'\\033[0m',pffScoutingData_df.isna().sum())\nprint('\\033[1m'\"Missing value count in each column of games data file\\n\"'\\033[0m',games_df.isna().sum())\nprint('\\033[1m'\"Missing value count in each column of plays data file\\n\"'\\033[0m',plays_df.isna().sum())\nprint('\\033[1m'\"Missing value count in each column of tracking 2018 data file\\n\"'\\033[0m',tracking18_df.isna().sum())\nprint('\\033[1m'\"Missing value count in each column of tracking 2019 data file\\n\"'\\033[0m',tracking19_df.isna().sum())\nprint('\\033[1m'\"Missing value count in each column of tracking 2020 data file\\n\"'\\033[0m',tracking20_df.isna().sum())","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:28.920987Z","iopub.execute_input":"2022-01-25T09:07:28.921744Z","iopub.status.idle":"2022-01-25T09:07:52.91519Z","shell.execute_reply.started":"2022-01-25T09:07:28.921681Z","shell.execute_reply":"2022-01-25T09:07:52.914409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Visualize missing values as a matrix\n\nmsno.heatmap(players_df,figsize=(10,5))","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:52.916508Z","iopub.execute_input":"2022-01-25T09:07:52.917305Z","iopub.status.idle":"2022-01-25T09:07:53.265354Z","shell.execute_reply.started":"2022-01-25T09:07:52.917264Z","shell.execute_reply":"2022-01-25T09:07:53.264582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"msno.heatmap(pffScoutingData_df,figsize=(10,5))","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:53.267205Z","iopub.execute_input":"2022-01-25T09:07:53.267972Z","iopub.status.idle":"2022-01-25T09:07:54.652994Z","shell.execute_reply.started":"2022-01-25T09:07:53.267927Z","shell.execute_reply":"2022-01-25T09:07:54.652213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"msno.heatmap(plays_df,figsize=(10,5))","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:54.654041Z","iopub.execute_input":"2022-01-25T09:07:54.654285Z","iopub.status.idle":"2022-01-25T09:07:55.323327Z","shell.execute_reply.started":"2022-01-25T09:07:54.654238Z","shell.execute_reply":"2022-01-25T09:07:55.322608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div class=\"alert alert-block alert-success\">  \n<h2><center><strong>Analysis of Game Dataframe </strong></center></h2>\n</div>","metadata":{}},{"cell_type":"code","source":"#First five records \n\ncolorscale = [[0, 'red'],[.5, '#DCE775'],[1, '#C0CA33']]\nfont=['white', '#212121' , 'red']\nfig = ff.create_table(games_df.head(5),height_constant=50,colorscale=colorscale,font_colors=font)\nfor i in range(len(fig.layout.annotations)):\n    fig.layout.annotations[i].font.size = 17\nfig.update_layout(width=4500, height=400)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:55.325103Z","iopub.execute_input":"2022-01-25T09:07:55.325783Z","iopub.status.idle":"2022-01-25T09:07:55.513174Z","shell.execute_reply.started":"2022-01-25T09:07:55.325738Z","shell.execute_reply":"2022-01-25T09:07:55.512341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:55.515097Z","iopub.execute_input":"2022-01-25T09:07:55.515358Z","iopub.status.idle":"2022-01-25T09:07:55.522608Z","shell.execute_reply.started":"2022-01-25T09:07:55.515324Z","shell.execute_reply":"2022-01-25T09:07:55.521665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Descriptive statistics \n\ngames_df.describe().T","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:55.529047Z","iopub.execute_input":"2022-01-25T09:07:55.52935Z","iopub.status.idle":"2022-01-25T09:07:55.573241Z","shell.execute_reply.started":"2022-01-25T09:07:55.529313Z","shell.execute_reply":"2022-01-25T09:07:55.572483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# No of unique games \n\ngames_df[\"gameId\"].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:55.575042Z","iopub.execute_input":"2022-01-25T09:07:55.575769Z","iopub.status.idle":"2022-01-25T09:07:55.58494Z","shell.execute_reply.started":"2022-01-25T09:07:55.575725Z","shell.execute_reply":"2022-01-25T09:07:55.584016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = go.Pie(\nvalues= games_df[\"season\"].value_counts(),\nlabels= games_df[\"season\"].value_counts().index,\n)\nlayout = go.Layout(\ntitle=dict(text = \"No of games for season\",x=0.46,y=0.95,font_size=20)\n)\nfig = go.Figure(data=data,layout=layout)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:55.587132Z","iopub.execute_input":"2022-01-25T09:07:55.588213Z","iopub.status.idle":"2022-01-25T09:07:55.629113Z","shell.execute_reply.started":"2022-01-25T09:07:55.588168Z","shell.execute_reply":"2022-01-25T09:07:55.628285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Time Attributes ","metadata":{}},{"cell_type":"code","source":"games_df['month'] = games_df['gameDate'].apply(lambda x: int(x.split('/')[0]))\ngames_df['day'] = games_df['gameDate'].apply(lambda x: int(x.split('/')[1]))\ngames_df['hour'] = games_df['gameTimeEastern'].apply(lambda x: int(x.split(':')[0]))","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:55.631059Z","iopub.execute_input":"2022-01-25T09:07:55.631912Z","iopub.status.idle":"2022-01-25T09:07:55.648924Z","shell.execute_reply.started":"2022-01-25T09:07:55.631864Z","shell.execute_reply":"2022-01-25T09:07:55.648071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = go.Pie(\nvalues= games_df[\"month\"].value_counts(),\nlabels= games_df[\"month\"].value_counts().index,\n)\nlayout = go.Layout(\ntitle=dict(text = \"No of games for month\",x=0.46,y=0.95,font_size=20)\n)\nfig = go.Figure(data=data,layout=layout)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:55.650791Z","iopub.execute_input":"2022-01-25T09:07:55.65158Z","iopub.status.idle":"2022-01-25T09:07:55.672315Z","shell.execute_reply.started":"2022-01-25T09:07:55.651518Z","shell.execute_reply":"2022-01-25T09:07:55.671435Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = go.Pie(\nvalues= games_df[\"day\"].value_counts(),\nlabels= games_df[\"day\"].value_counts().index,\n)\nlayout = go.Layout(\ntitle=dict(text = \"No of games for day\",x=0.46,y=0.95,font_size=20)\n)\nfig = go.Figure(data=data,layout=layout)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:55.674245Z","iopub.execute_input":"2022-01-25T09:07:55.675025Z","iopub.status.idle":"2022-01-25T09:07:55.694926Z","shell.execute_reply.started":"2022-01-25T09:07:55.674981Z","shell.execute_reply":"2022-01-25T09:07:55.694172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = go.Pie(\nvalues= games_df[\"hour\"].value_counts(),\nlabels= games_df[\"hour\"].value_counts().index,\n)\nlayout = go.Layout(\ntitle=dict(text = \"No of games for hour\",x=0.46,y=0.95,font_size=20)\n)\nfig = go.Figure(data=data,layout=layout)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:55.696828Z","iopub.execute_input":"2022-01-25T09:07:55.697569Z","iopub.status.idle":"2022-01-25T09:07:55.717736Z","shell.execute_reply.started":"2022-01-25T09:07:55.697516Z","shell.execute_reply":"2022-01-25T09:07:55.716872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(16, 10))\nax=sns.countplot(x=\"gameTimeEastern\",data=games_df,order=games_df.gameTimeEastern.value_counts().index,palette=\"Dark2_r\",linewidth=3)\nax.bar_label(ax.containers[0])\nplt.title(\"No of games for gametimeEastern\",font=\"Serif\", size=20)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:55.719783Z","iopub.execute_input":"2022-01-25T09:07:55.720514Z","iopub.status.idle":"2022-01-25T09:07:56.15341Z","shell.execute_reply.started":"2022-01-25T09:07:55.720469Z","shell.execute_reply":"2022-01-25T09:07:56.152504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels = list(games_df.week.value_counts().index)\nvalues = games_df['week'].value_counts()\nfig = go.Figure(data=[go.Pie(labels=labels,\n                             values=values,hole=.3)])\nfig.update_traces(hoverinfo='label+percent', textinfo='percent', textfont_size=20,\n                  marker=dict( line=dict(color='#000000', width=3)))\nfig.update_layout(title=\"No of games for week\",\n                  titlefont={'size': 30},      \n                  )\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:56.155036Z","iopub.execute_input":"2022-01-25T09:07:56.155842Z","iopub.status.idle":"2022-01-25T09:07:56.19868Z","shell.execute_reply.started":"2022-01-25T09:07:56.155799Z","shell.execute_reply":"2022-01-25T09:07:56.197858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div class=\"alert alert-block alert-success\">  \n<h2><center><strong>Analysis of Players Dataframe </strong></center></h2>\n</div>","metadata":{}},{"cell_type":"code","source":"fig = ff.create_table(players_df.head(5),height_constant=50)\nfig.update_layout(width=3500, height=400)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:56.200351Z","iopub.execute_input":"2022-01-25T09:07:56.200627Z","iopub.status.idle":"2022-01-25T09:07:56.254682Z","shell.execute_reply.started":"2022-01-25T09:07:56.20059Z","shell.execute_reply":"2022-01-25T09:07:56.253766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Shape of the data \n\nplayers_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:56.256648Z","iopub.execute_input":"2022-01-25T09:07:56.256954Z","iopub.status.idle":"2022-01-25T09:07:56.263701Z","shell.execute_reply.started":"2022-01-25T09:07:56.256915Z","shell.execute_reply":"2022-01-25T09:07:56.26289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#No of unique players \n\nplayers_df['nflId'].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:56.265363Z","iopub.execute_input":"2022-01-25T09:07:56.265649Z","iopub.status.idle":"2022-01-25T09:07:56.278162Z","shell.execute_reply.started":"2022-01-25T09:07:56.265608Z","shell.execute_reply":"2022-01-25T09:07:56.277015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(16, 10))\nax=sns.countplot(x=\"height\",data=players_df,order=players_df.height.value_counts().index,palette=\"Dark2_r\",linewidth=3)\nax.bar_label(ax.containers[0])\nplt.title(\"Height of the players\",font=\"Serif\", size=20)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:56.279263Z","iopub.execute_input":"2022-01-25T09:07:56.279934Z","iopub.status.idle":"2022-01-25T09:07:56.87833Z","shell.execute_reply.started":"2022-01-25T09:07:56.279893Z","shell.execute_reply":"2022-01-25T09:07:56.877587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"height_df = players_df['height'].str.split('-',expand=True)\n\nheight_df.columns = [\n    'feet', \n    'inches'\n]\n\nheight_df.loc[(height_df['inches'].notnull()), 'feet'] = height_df[height_df['inches'].notnull()]['feet'].astype(np.int16) * 12 + height_df[height_df['inches'].notnull()]['inches'].astype(np.int16)","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:56.879895Z","iopub.execute_input":"2022-01-25T09:07:56.880846Z","iopub.status.idle":"2022-01-25T09:07:56.905453Z","shell.execute_reply.started":"2022-01-25T09:07:56.880804Z","shell.execute_reply":"2022-01-25T09:07:56.904642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players_df['height'] = height_df['feet']\nplayers_df['height'] = players_df['height'].astype(np.float32)\nplayers_df['height'] /= 12","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:56.90717Z","iopub.execute_input":"2022-01-25T09:07:56.907898Z","iopub.status.idle":"2022-01-25T09:07:56.916038Z","shell.execute_reply.started":"2022-01-25T09:07:56.907843Z","shell.execute_reply":"2022-01-25T09:07:56.914975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"group_labels = ['Height Distribution']\nhist_data = [players_df[\"height\"]]\nfig = ff.create_distplot(hist_data,group_labels, bin_size=[2])\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:56.917941Z","iopub.execute_input":"2022-01-25T09:07:56.918381Z","iopub.status.idle":"2022-01-25T09:07:57.035823Z","shell.execute_reply.started":"2022-01-25T09:07:56.918341Z","shell.execute_reply":"2022-01-25T09:07:57.035135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"group_labels = ['Weight Distribution']\nhist_data = [players_df[\"weight\"]]\nfig = ff.create_distplot(hist_data,group_labels, bin_size=[20])\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:57.037382Z","iopub.execute_input":"2022-01-25T09:07:57.038365Z","iopub.status.idle":"2022-01-25T09:07:57.117357Z","shell.execute_reply.started":"2022-01-25T09:07:57.038325Z","shell.execute_reply":"2022-01-25T09:07:57.116442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels = list(players_df.Position.value_counts().index)\nvalues = players_df['Position'].value_counts()\nfig = go.Figure(data=[go.Pie(labels=labels,\n                             values=values,hole=.3)])\nfig.update_traces(hoverinfo='label+percent', textinfo='percent', textfont_size=20,\n                  marker=dict( line=dict(color='#000000', width=3)))\nfig.update_layout(title=\"No of Positions for players\",\n                  titlefont={'size': 30},      \n                  )\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:57.118874Z","iopub.execute_input":"2022-01-25T09:07:57.119214Z","iopub.status.idle":"2022-01-25T09:07:57.147507Z","shell.execute_reply.started":"2022-01-25T09:07:57.119175Z","shell.execute_reply":"2022-01-25T09:07:57.14667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(16, 10))\nax=sns.countplot(y=\"collegeName\",data=players_df,order=players_df.collegeName.value_counts().iloc[:20].index,palette=\"Dark2_r\",linewidth=3)\nax.bar_label(ax.containers[0])\nplt.title(\"No of colleges for players\",font=\"Serif\", size=20)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:57.14912Z","iopub.execute_input":"2022-01-25T09:07:57.149385Z","iopub.status.idle":"2022-01-25T09:07:57.581127Z","shell.execute_reply.started":"2022-01-25T09:07:57.14935Z","shell.execute_reply":"2022-01-25T09:07:57.579762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Players Date of Birth Analysis ","metadata":{}},{"cell_type":"code","source":"players_df[\"birthYear\"] = 0\nplayers_df[\"birthMonth\"] = 0\n#There are NA values in birthDate so that we should drop them\nplayers_df.dropna(subset=[\"birthDate\"], inplace=True)\nfor idx, row in players_df.iterrows():\n    if len(row['birthDate'].split('/')) == 3: \n        players_df.loc[idx, 'birthYear'] = row['birthDate'].split('/')[2]\n        players_df.loc[idx, 'birthMonth'] = row['birthDate'].split('/')[0]\n        \n    elif len(row['birthDate'].split('-')) == 3: \n        players_df.loc[idx, 'birthYear'] = row['birthDate'].split('-')[0]\n        players_df.loc[idx, 'birthMonth'] = row['birthDate'].split('-')[1]","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:57.582834Z","iopub.execute_input":"2022-01-25T09:07:57.583489Z","iopub.status.idle":"2022-01-25T09:07:59.205329Z","shell.execute_reply.started":"2022-01-25T09:07:57.583451Z","shell.execute_reply":"2022-01-25T09:07:59.204484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(16, 10))\nax=sns.countplot(x=\"birthYear\",data=players_df,order=players_df.birthYear.value_counts().index,palette=\"Dark2_r\",linewidth=3)\nax.bar_label(ax.containers[0])\nplt.title(\"Birth Year of the players\",font=\"Serif\", size=20)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:59.206779Z","iopub.execute_input":"2022-01-25T09:07:59.207062Z","iopub.status.idle":"2022-01-25T09:07:59.732475Z","shell.execute_reply.started":"2022-01-25T09:07:59.207026Z","shell.execute_reply":"2022-01-25T09:07:59.731674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = go.Pie(\nvalues= players_df[\"birthMonth\"].value_counts(),\nlabels= players_df[\"birthMonth\"].value_counts().index,\n)\nlayout = go.Layout(\ntitle=dict(text = \"Birth Month for players\",x=0.46,y=0.95,font_size=20)\n)\nfig = go.Figure(data=data,layout=layout)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:59.733735Z","iopub.execute_input":"2022-01-25T09:07:59.734508Z","iopub.status.idle":"2022-01-25T09:07:59.755406Z","shell.execute_reply.started":"2022-01-25T09:07:59.734465Z","shell.execute_reply":"2022-01-25T09:07:59.754431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cloud = WordCloud(width=1440, height=1080,stopwords={'nan'}).generate(\" \".join(players_df['collegeName'].astype(str)))\nplt.figure(figsize=(15, 10))\nplt.imshow(cloud)\nplt.axis('off')","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:07:59.757343Z","iopub.execute_input":"2022-01-25T09:07:59.758218Z","iopub.status.idle":"2022-01-25T09:08:03.930129Z","shell.execute_reply.started":"2022-01-25T09:07:59.758172Z","shell.execute_reply":"2022-01-25T09:08:03.929237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cloud = WordCloud(width=1440, height=1080,stopwords={'nan'}).generate(\" \".join(players_df['displayName'].astype(str)))\nplt.figure(figsize=(15, 10))\nplt.imshow(cloud)\nplt.axis('off')","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:08:03.93219Z","iopub.execute_input":"2022-01-25T09:08:03.932537Z","iopub.status.idle":"2022-01-25T09:08:08.108926Z","shell.execute_reply.started":"2022-01-25T09:08:03.932487Z","shell.execute_reply":"2022-01-25T09:08:08.108196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div class=\"alert alert-block alert-success\">  \n<h2><center><strong>Analysis of Play Dataframe </strong></center></h2>\n</div>","metadata":{}},{"cell_type":"code","source":"plays_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:08:08.109938Z","iopub.execute_input":"2022-01-25T09:08:08.110291Z","iopub.status.idle":"2022-01-25T09:08:08.146642Z","shell.execute_reply.started":"2022-01-25T09:08:08.11026Z","shell.execute_reply":"2022-01-25T09:08:08.145984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plays_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:08:08.147797Z","iopub.execute_input":"2022-01-25T09:08:08.148863Z","iopub.status.idle":"2022-01-25T09:08:08.155266Z","shell.execute_reply.started":"2022-01-25T09:08:08.148807Z","shell.execute_reply":"2022-01-25T09:08:08.154568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plays_df.describe().T","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:08:08.157356Z","iopub.execute_input":"2022-01-25T09:08:08.158409Z","iopub.status.idle":"2022-01-25T09:08:08.242876Z","shell.execute_reply.started":"2022-01-25T09:08:08.15837Z","shell.execute_reply":"2022-01-25T09:08:08.24198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 10))\nax=sns.countplot(x=\"quarter\",data=plays_df,order=plays_df.quarter.value_counts().index,palette=\"Dark2_r\",linewidth=3)\nax.bar_label(ax.containers[0])\nplt.title(\"No of plays in every quarter\",font=\"Serif\", size=20)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:14:18.897823Z","iopub.execute_input":"2022-01-25T09:14:18.898376Z","iopub.status.idle":"2022-01-25T09:14:19.121144Z","shell.execute_reply.started":"2022-01-25T09:14:18.898337Z","shell.execute_reply":"2022-01-25T09:14:19.119501Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = go.Pie(\nvalues= plays_df[\"down\"].value_counts(),\nlabels= plays_df[\"down\"].value_counts().index,\n)\nlayout = go.Layout(\ntitle=dict(text = \"No of plays of every down\",x=0.46,y=0.95,font_size=20)\n)\nfig = go.Figure(data=data,layout=layout)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:15:58.685812Z","iopub.execute_input":"2022-01-25T09:15:58.68632Z","iopub.status.idle":"2022-01-25T09:15:58.700602Z","shell.execute_reply.started":"2022-01-25T09:15:58.686281Z","shell.execute_reply":"2022-01-25T09:15:58.699769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 10))\nax=sns.countplot(x=\"yardsToGo\",data=plays_df,order=plays_df.yardsToGo.value_counts().index,palette=\"Dark2_r\",linewidth=3)\nax.bar_label(ax.containers[0])\nplt.title(\"Number of plays for every yards to go category\",font=\"Serif\", size=20)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:19:19.48729Z","iopub.execute_input":"2022-01-25T09:19:19.487557Z","iopub.status.idle":"2022-01-25T09:19:20.117168Z","shell.execute_reply.started":"2022-01-25T09:19:19.487528Z","shell.execute_reply":"2022-01-25T09:19:20.115675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"group_labels = ['PlayResult Distribution']\nhist_data = [plays_df[\"playResult\"]]\nfig = ff.create_distplot(hist_data,group_labels, bin_size=[2])\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:20:51.25505Z","iopub.execute_input":"2022-01-25T09:20:51.255924Z","iopub.status.idle":"2022-01-25T09:20:51.615267Z","shell.execute_reply.started":"2022-01-25T09:20:51.255867Z","shell.execute_reply":"2022-01-25T09:20:51.614578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"group_labels = ['PreSnapHomeScore Distribution']\nhist_data = [plays_df[\"preSnapHomeScore\"]]\nfig = ff.create_distplot(hist_data,group_labels, bin_size=[2])\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:22:02.492363Z","iopub.execute_input":"2022-01-25T09:22:02.492672Z","iopub.status.idle":"2022-01-25T09:22:02.850124Z","shell.execute_reply.started":"2022-01-25T09:22:02.492641Z","shell.execute_reply":"2022-01-25T09:22:02.846767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"group_labels = ['PreSnapVisitorScore Distribution']\nhist_data = [plays_df[\"preSnapVisitorScore\"]]\nfig = ff.create_distplot(hist_data,group_labels, bin_size=[2])\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-25T09:23:36.618682Z","iopub.execute_input":"2022-01-25T09:23:36.619267Z","iopub.status.idle":"2022-01-25T09:23:37.088192Z","shell.execute_reply.started":"2022-01-25T09:23:36.619229Z","shell.execute_reply":"2022-01-25T09:23:37.08729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}