{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\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# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-10-12T14:50:48.526215Z","iopub.execute_input":"2021-10-12T14:50:48.526543Z","iopub.status.idle":"2021-10-12T14:50:48.538719Z","shell.execute_reply.started":"2021-10-12T14:50:48.526512Z","shell.execute_reply":"2021-10-12T14:50:48.537426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 1. Introduction\n- The National Football League (NFL) is a professional American football league \n- The NFL is one of the four major North American professional sports leagues, the highest professional level of American football in the world.\n- The NFL's eighteen-week regular season runs from early September to early January, with each team playing seventeen games and having one bye week.\n- The NFL was formed in 1920 as the American Professional Football Association (APFA) before renaming itself the National Football League for the 1922 season. ","metadata":{}},{"cell_type":"markdown","source":"**Will keep updating**","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"![](http://unsplash.com/photos/0ndQ1W0w99Q)","metadata":{}},{"cell_type":"markdown","source":"# 2. Games Dataset","metadata":{}},{"cell_type":"code","source":"df_game = pd.read_csv('../input/nfl-big-data-bowl-2022/games.csv')","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:48.541043Z","iopub.execute_input":"2021-10-12T14:50:48.541335Z","iopub.status.idle":"2021-10-12T14:50:48.566908Z","shell.execute_reply.started":"2021-10-12T14:50:48.541305Z","shell.execute_reply":"2021-10-12T14:50:48.565795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Dataset Description ","metadata":{}},{"cell_type":"markdown","source":"|**Column Name**|**Description**|\n| :-- | :--\n|**gameId**|Game identifier, unique|\n|**gameDate**|Game Date (time, mm/dd/yyyy)|\n|**gameTimeEastern**|Start time of game (time, HH:MM:SS, EST)|\n|**homeTeamAbbr**|Home team three-letter code|\n|**visitorTeamAbbr**|Visiting team three-letter code|\n|**week**|Week of game|","metadata":{"execution":{"iopub.status.busy":"2021-10-02T14:57:14.479848Z","iopub.execute_input":"2021-10-02T14:57:14.481015Z","iopub.status.idle":"2021-10-02T14:57:14.491376Z","shell.execute_reply.started":"2021-10-02T14:57:14.480951Z","shell.execute_reply":"2021-10-02T14:57:14.49031Z"}}},{"cell_type":"code","source":"df_game.head()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:48.568329Z","iopub.execute_input":"2021-10-12T14:50:48.568616Z","iopub.status.idle":"2021-10-12T14:50:48.594548Z","shell.execute_reply.started":"2021-10-12T14:50:48.568587Z","shell.execute_reply":"2021-10-12T14:50:48.593464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Dataset Shape**","metadata":{}},{"cell_type":"code","source":"df_game.shape","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:48.597213Z","iopub.execute_input":"2021-10-12T14:50:48.598067Z","iopub.status.idle":"2021-10-12T14:50:48.605362Z","shell.execute_reply.started":"2021-10-12T14:50:48.598006Z","shell.execute_reply":"2021-10-12T14:50:48.604083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Samples total - 764 Dimensionality - 7**","metadata":{}},{"cell_type":"markdown","source":"**Dataset Type**","metadata":{}},{"cell_type":"code","source":"df_game.info()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:48.606890Z","iopub.execute_input":"2021-10-12T14:50:48.607804Z","iopub.status.idle":"2021-10-12T14:50:48.639244Z","shell.execute_reply.started":"2021-10-12T14:50:48.607759Z","shell.execute_reply":"2021-10-12T14:50:48.638211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Dataset has a mixture of 4 categorical and 3 numerical data**","metadata":{}},{"cell_type":"markdown","source":"**Checking for missing values**","metadata":{}},{"cell_type":"code","source":"df_game.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:48.640742Z","iopub.execute_input":"2021-10-12T14:50:48.641518Z","iopub.status.idle":"2021-10-12T14:50:48.657300Z","shell.execute_reply.started":"2021-10-12T14:50:48.641484Z","shell.execute_reply":"2021-10-12T14:50:48.656614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**There are no missing values**","metadata":{}},{"cell_type":"markdown","source":"# 3. EDA","metadata":{}},{"cell_type":"markdown","source":"**Number of games played in each season**","metadata":{}},{"cell_type":"code","source":"df_game['season'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:48.658870Z","iopub.execute_input":"2021-10-12T14:50:48.659199Z","iopub.status.idle":"2021-10-12T14:50:48.674482Z","shell.execute_reply.started":"2021-10-12T14:50:48.659116Z","shell.execute_reply":"2021-10-12T14:50:48.673335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nlabels = ['2020','2019','2018']\nsizes =[256, 255,253]\ncolors = ['gold','lightskyblue', 'green']\nexplode = (0.1, 0,0)  \n\nplt.pie(sizes, explode=explode, labels=labels, colors=colors, \n        autopct='%1.1f%%', shadow=True, startangle=140)\n\nplt.axis('equal')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:48.675823Z","iopub.execute_input":"2021-10-12T14:50:48.676386Z","iopub.status.idle":"2021-10-12T14:50:48.851609Z","shell.execute_reply.started":"2021-10-12T14:50:48.676339Z","shell.execute_reply":"2021-10-12T14:50:48.850643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**256 regular season games were played in 2020**","metadata":{}},{"cell_type":"markdown","source":"**Feature Engineering**","metadata":{}},{"cell_type":"code","source":"df_game['month'] = df_game['gameDate'].apply(lambda x: int(x.split('/')[0]))","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:48.853207Z","iopub.execute_input":"2021-10-12T14:50:48.853441Z","iopub.status.idle":"2021-10-12T14:50:48.862320Z","shell.execute_reply.started":"2021-10-12T14:50:48.853413Z","shell.execute_reply":"2021-10-12T14:50:48.861149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_game['day'] = df_game['gameDate'].apply(lambda x: int(x.split('/')[1]))","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:48.866915Z","iopub.execute_input":"2021-10-12T14:50:48.867930Z","iopub.status.idle":"2021-10-12T14:50:48.877784Z","shell.execute_reply.started":"2021-10-12T14:50:48.867807Z","shell.execute_reply":"2021-10-12T14:50:48.876689Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_game['hour'] = df_game['gameTimeEastern'].apply(lambda x: int(x.split(':')[0]))","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:48.879099Z","iopub.execute_input":"2021-10-12T14:50:48.879324Z","iopub.status.idle":"2021-10-12T14:50:48.895215Z","shell.execute_reply.started":"2021-10-12T14:50:48.879298Z","shell.execute_reply":"2021-10-12T14:50:48.893633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_game['month'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:48.896682Z","iopub.execute_input":"2021-10-12T14:50:48.896907Z","iopub.status.idle":"2021-10-12T14:50:48.912241Z","shell.execute_reply.started":"2021-10-12T14:50:48.896880Z","shell.execute_reply":"2021-10-12T14:50:48.911382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nplt.figure(figsize=(7,7))\nsns.countplot(x=\"month\", data=df_game)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:48.913587Z","iopub.execute_input":"2021-10-12T14:50:48.913846Z","iopub.status.idle":"2021-10-12T14:50:50.038371Z","shell.execute_reply.started":"2021-10-12T14:50:48.913818Z","shell.execute_reply":"2021-10-12T14:50:50.037355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(16,7))\nsns.countplot(x=\"day\", data=df_game)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:50.039761Z","iopub.execute_input":"2021-10-12T14:50:50.040928Z","iopub.status.idle":"2021-10-12T14:50:50.441562Z","shell.execute_reply.started":"2021-10-12T14:50:50.040875Z","shell.execute_reply":"2021-10-12T14:50:50.440389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,5))\nsns.countplot(x=\"hour\", data=df_game)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:50.443595Z","iopub.execute_input":"2021-10-12T14:50:50.444318Z","iopub.status.idle":"2021-10-12T14:50:50.685841Z","shell.execute_reply.started":"2021-10-12T14:50:50.444256Z","shell.execute_reply":"2021-10-12T14:50:50.684712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,5))\nsns.countplot(x=\"gameTimeEastern\", data=df_game)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:50.687716Z","iopub.execute_input":"2021-10-12T14:50:50.688036Z","iopub.status.idle":"2021-10-12T14:50:50.998912Z","shell.execute_reply.started":"2021-10-12T14:50:50.687997Z","shell.execute_reply":"2021-10-12T14:50:50.997451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Majority of games were played at 13:00 hrs, 16:00 hrs, and 20:00 hrs onwards**","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(15,5))\nsns.countplot(x=\"week\", data=df_game)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:51.000702Z","iopub.execute_input":"2021-10-12T14:50:51.001544Z","iopub.status.idle":"2021-10-12T14:50:51.422715Z","shell.execute_reply.started":"2021-10-12T14:50:51.001499Z","shell.execute_reply":"2021-10-12T14:50:51.421569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**All 256 regular season games were played within the original 17-week span**","metadata":{}},{"cell_type":"code","source":"x=df_game.corr()\nx","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:51.424048Z","iopub.execute_input":"2021-10-12T14:50:51.424452Z","iopub.status.idle":"2021-10-12T14:50:51.441134Z","shell.execute_reply.started":"2021-10-12T14:50:51.424421Z","shell.execute_reply":"2021-10-12T14:50:51.440043Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(14,6))\nsns.heatmap(x, annot=True)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:51.442554Z","iopub.execute_input":"2021-10-12T14:50:51.442812Z","iopub.status.idle":"2021-10-12T14:50:51.891950Z","shell.execute_reply.started":"2021-10-12T14:50:51.442783Z","shell.execute_reply":"2021-10-12T14:50:51.891009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 4. Players","metadata":{}},{"cell_type":"markdown","source":"|**Column Name**|**Description**|\n| :-- | :--\n|**nflId**|Player identification number, unique across players|\n|**height**|Player height|\n|**weight**|Player weight|\n|**birthDate**|Date of birth (YYYY-MM-DD)|\n|**collegeName**|Player college|\n|**position**|Player position|\n|**displayName**|Player name|","metadata":{}},{"cell_type":"code","source":"df_player=pd.read_csv('../input/nfl-big-data-bowl-2022/players.csv')","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:51.893558Z","iopub.execute_input":"2021-10-12T14:50:51.894939Z","iopub.status.idle":"2021-10-12T14:50:51.916877Z","shell.execute_reply.started":"2021-10-12T14:50:51.894881Z","shell.execute_reply":"2021-10-12T14:50:51.915961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Dataset Shape**","metadata":{}},{"cell_type":"code","source":"df_player.shape","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:51.918355Z","iopub.execute_input":"2021-10-12T14:50:51.918703Z","iopub.status.idle":"2021-10-12T14:50:51.927160Z","shell.execute_reply.started":"2021-10-12T14:50:51.918663Z","shell.execute_reply":"2021-10-12T14:50:51.926068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Samples total - 2732 Dimensionality - 7**","metadata":{}},{"cell_type":"markdown","source":"**Dataset Type**","metadata":{}},{"cell_type":"code","source":"df_player.info()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:51.928638Z","iopub.execute_input":"2021-10-12T14:50:51.928995Z","iopub.status.idle":"2021-10-12T14:50:51.951709Z","shell.execute_reply.started":"2021-10-12T14:50:51.928966Z","shell.execute_reply":"2021-10-12T14:50:51.950754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Dataset has a mixture of 5 categorical and 2 numerical data**","metadata":{}},{"cell_type":"markdown","source":"**Checking for missing values**","metadata":{}},{"cell_type":"code","source":"df_player.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:51.952791Z","iopub.execute_input":"2021-10-12T14:50:51.953044Z","iopub.status.idle":"2021-10-12T14:50:51.974235Z","shell.execute_reply.started":"2021-10-12T14:50:51.953017Z","shell.execute_reply":"2021-10-12T14:50:51.973107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_player.describe(include='all')","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:51.975818Z","iopub.execute_input":"2021-10-12T14:50:51.976587Z","iopub.status.idle":"2021-10-12T14:50:52.020065Z","shell.execute_reply.started":"2021-10-12T14:50:51.976547Z","shell.execute_reply":"2021-10-12T14:50:52.019124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_player['height'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:52.021402Z","iopub.execute_input":"2021-10-12T14:50:52.022325Z","iopub.status.idle":"2021-10-12T14:50:52.031758Z","shell.execute_reply.started":"2021-10-12T14:50:52.022286Z","shell.execute_reply":"2021-10-12T14:50:52.030749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Feature Engineering**","metadata":{}},{"cell_type":"code","source":"check = df_player['height'].str.split('-',expand=True)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:52.036378Z","iopub.execute_input":"2021-10-12T14:50:52.036677Z","iopub.status.idle":"2021-10-12T14:50:52.049433Z","shell.execute_reply.started":"2021-10-12T14:50:52.036645Z","shell.execute_reply":"2021-10-12T14:50:52.048606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check.columns=['first', 'second']","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:52.050541Z","iopub.execute_input":"2021-10-12T14:50:52.050787Z","iopub.status.idle":"2021-10-12T14:50:52.063787Z","shell.execute_reply.started":"2021-10-12T14:50:52.050759Z","shell.execute_reply":"2021-10-12T14:50:52.062804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check.loc[(check['second'].notnull()),'first'] = check[check['second'].notnull()]['first'].astype(np.int64)*12+check[check['second'].notnull()]['second'].astype(np.int16)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:52.065459Z","iopub.execute_input":"2021-10-12T14:50:52.065738Z","iopub.status.idle":"2021-10-12T14:50:52.084381Z","shell.execute_reply.started":"2021-10-12T14:50:52.065707Z","shell.execute_reply":"2021-10-12T14:50:52.083246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_player['height']=check['first']","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:52.086544Z","iopub.execute_input":"2021-10-12T14:50:52.086926Z","iopub.status.idle":"2021-10-12T14:50:52.096785Z","shell.execute_reply.started":"2021-10-12T14:50:52.086871Z","shell.execute_reply":"2021-10-12T14:50:52.095495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_player['height']= df_player['height'].astype(np.float32)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:52.098793Z","iopub.execute_input":"2021-10-12T14:50:52.099068Z","iopub.status.idle":"2021-10-12T14:50:52.109250Z","shell.execute_reply.started":"2021-10-12T14:50:52.099040Z","shell.execute_reply":"2021-10-12T14:50:52.108540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_player['height']/= 12","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:52.110611Z","iopub.execute_input":"2021-10-12T14:50:52.111017Z","iopub.status.idle":"2021-10-12T14:50:52.123964Z","shell.execute_reply.started":"2021-10-12T14:50:52.110890Z","shell.execute_reply":"2021-10-12T14:50:52.123252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_player","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:52.125386Z","iopub.execute_input":"2021-10-12T14:50:52.126803Z","iopub.status.idle":"2021-10-12T14:50:52.151455Z","shell.execute_reply.started":"2021-10-12T14:50:52.126746Z","shell.execute_reply":"2021-10-12T14:50:52.150066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_player['height']","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:52.153333Z","iopub.execute_input":"2021-10-12T14:50:52.153758Z","iopub.status.idle":"2021-10-12T14:50:52.167395Z","shell.execute_reply.started":"2021-10-12T14:50:52.153696Z","shell.execute_reply":"2021-10-12T14:50:52.166217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.distplot(df_player['height'], color='b')","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:52.169018Z","iopub.execute_input":"2021-10-12T14:50:52.169384Z","iopub.status.idle":"2021-10-12T14:50:52.504181Z","shell.execute_reply.started":"2021-10-12T14:50:52.169343Z","shell.execute_reply":"2021-10-12T14:50:52.503244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.distplot(df_player['weight'], color='g')","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:52.505584Z","iopub.execute_input":"2021-10-12T14:50:52.505844Z","iopub.status.idle":"2021-10-12T14:50:52.772287Z","shell.execute_reply.started":"2021-10-12T14:50:52.505817Z","shell.execute_reply":"2021-10-12T14:50:52.771193Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_player['collegeName'].value_counts().sort_values(ascending=False)[:20]","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:52.773344Z","iopub.execute_input":"2021-10-12T14:50:52.773577Z","iopub.status.idle":"2021-10-12T14:50:52.784825Z","shell.execute_reply.started":"2021-10-12T14:50:52.773550Z","shell.execute_reply":"2021-10-12T14:50:52.783617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Top Colleges playing NFL\ndf_player['collegeName'].value_counts().sort_values(ascending=False)[:5].plot(kind='bar')","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:52.786482Z","iopub.execute_input":"2021-10-12T14:50:52.786826Z","iopub.status.idle":"2021-10-12T14:50:52.989743Z","shell.execute_reply.started":"2021-10-12T14:50:52.786782Z","shell.execute_reply":"2021-10-12T14:50:52.988722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_player['displayName'].value_counts().sort_values(ascending=False)[:5].plot(kind='bar')","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:52.991289Z","iopub.execute_input":"2021-10-12T14:50:52.991626Z","iopub.status.idle":"2021-10-12T14:50:53.179592Z","shell.execute_reply.started":"2021-10-12T14:50:52.991585Z","shell.execute_reply":"2021-10-12T14:50:53.178719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Top Players from different Colleges\nplt.figure(figsize=(14,7))\nsns.scatterplot(x=df_player['displayName'][:5], y=df_player['collegeName'][:5], data=df_player)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:53.181050Z","iopub.execute_input":"2021-10-12T14:50:53.181420Z","iopub.status.idle":"2021-10-12T14:50:53.378976Z","shell.execute_reply.started":"2021-10-12T14:50:53.181376Z","shell.execute_reply":"2021-10-12T14:50:53.377767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Football Abbreviations Positions\n**WR = Wide Receiver**\n**CB = Corner Back**\n**DE = Defensive End**\n**OLB = Outside Linebacker**\n**TE = Tight End**\n**T = Tackle**\n**RB = Running Back**\n**G = Guard**\n**DT = Defensive Tackle**\n**ILB = Inside Linebacker**\n**FS =  Free Safety**\n**SS = Strong Safety**\n**C = Center**\n**K = Placekicker**\n**P = Punter**\n**NT = Nose Tackle**\n**LS = Long Snapper**\n**LB = Line Backer**\n**DB = Defensive Backs**\n**MLB = Middle Line Backer**\n**FB = Fullback**\n**OT = Overtime**\n**QB = Quarterback**\n**OG = Own Goal**\n**S = Saftey**\n**HB = Halfback**","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(14,7))\nsns.barplot(x=df_player['Position'], y=df_player['height'], data=df_player)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:53.381248Z","iopub.execute_input":"2021-10-12T14:50:53.381634Z","iopub.status.idle":"2021-10-12T14:50:54.758565Z","shell.execute_reply.started":"2021-10-12T14:50:53.381588Z","shell.execute_reply":"2021-10-12T14:50:54.757603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"birthDate :\",df_player['birthDate'])","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:54.759843Z","iopub.execute_input":"2021-10-12T14:50:54.760115Z","iopub.status.idle":"2021-10-12T14:50:54.769181Z","shell.execute_reply.started":"2021-10-12T14:50:54.760071Z","shell.execute_reply":"2021-10-12T14:50:54.768062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from datetime import datetime","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:54.770980Z","iopub.execute_input":"2021-10-12T14:50:54.771367Z","iopub.status.idle":"2021-10-12T14:50:54.783084Z","shell.execute_reply.started":"2021-10-12T14:50:54.771316Z","shell.execute_reply":"2021-10-12T14:50:54.781775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from datetime import date","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:54.784707Z","iopub.execute_input":"2021-10-12T14:50:54.785658Z","iopub.status.idle":"2021-10-12T14:50:54.793761Z","shell.execute_reply.started":"2021-10-12T14:50:54.785589Z","shell.execute_reply":"2021-10-12T14:50:54.793142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_player['birthDate'] = pd.to_datetime(df_player['birthDate'], errors='coerce')","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:54.794918Z","iopub.execute_input":"2021-10-12T14:50:54.795572Z","iopub.status.idle":"2021-10-12T14:50:54.811786Z","shell.execute_reply.started":"2021-10-12T14:50:54.795541Z","shell.execute_reply":"2021-10-12T14:50:54.810892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_player['formatted_df'] = df_player[\"birthDate\"].dt.strftime(\"%Y\")\ndf_player['formatted_df']","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:54.812893Z","iopub.execute_input":"2021-10-12T14:50:54.813943Z","iopub.status.idle":"2021-10-12T14:50:54.850128Z","shell.execute_reply.started":"2021-10-12T14:50:54.813828Z","shell.execute_reply":"2021-10-12T14:50:54.849226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.distplot(df_player['formatted_df'], color='y')","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:54.851327Z","iopub.execute_input":"2021-10-12T14:50:54.851558Z","iopub.status.idle":"2021-10-12T14:50:55.203259Z","shell.execute_reply.started":"2021-10-12T14:50:54.851531Z","shell.execute_reply":"2021-10-12T14:50:55.202560Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Maximum year - 1972 and Minimum year - 1999**","metadata":{}},{"cell_type":"markdown","source":"# 5. Plays","metadata":{}},{"cell_type":"markdown","source":"**Dataset Description**","metadata":{}},{"cell_type":"markdown","source":"|**Column Name**|**Description**|\n| :-- | :--\n|**gameId**|Game identifier, unique|\n|**playId**|Play identifier, not unique across games|\n|**playDescription**|Description of play|\n|**quarter**|Game quarter|\n|**down**|Down|\n|**yardsToGo**|Distance needed for a first down|\n|**possessionTeam**|Team punting, placekicking or kicking off the ball|\n|**specialTeamsPlayType**|Formation of play: Extra Point, Field Goal, Kickoff or Punt|\n|**specialTeamsPlayResult**|Special Teams outcome of play dependent on play type: Blocked Kick Attempt, Blocked Punt, Downed, Fair Catch, Kick Attempt Good, Kick Attempt No Good, Kickoff Team Recovery, Muffed, Non-Special Teams Result, Out of Bounds, Return or Touchback|\n|**kickerId**|nflId of placekicker, punter or kickoff specialist on play|\n|**returnerId**|nflId(s) of returner(s) on play if there was a special teams return. Multiple returners on a play are separated by a ;|\n|**kickBlockerId**|nflId of blocker of kick on play if there was a blocked field goal or blocked punt|\n|**yardlineSide**|3-letter team code corresponding to line-of-scrimmage|\n|**yardlineNumber**|Yard line at line-of-scrimmage|\n|**gameClock**|Time on clock of play (MM:SS)|\n|**penaltyCodes**|NFL categorization of the penalties that occurred on the play. Multiple penalties on a play are separated by a ;|\n|**penaltyJerseyNumber**|Jersey number and team code of the player committing each penalty. Multiple penalties on a play are separated by a ;|\n|**penaltyYards**|yards gained by possessionTeam by penalty|\n|**preSnapHomeScore**|Home score prior to the play|\n|**preSnapVisitorScore**|Visiting team score prior to the play|\n|**passResult**|Scrimmage outcome of the play if specialTeamsPlayResult is \"Non-Special Teams Result\" (C: Complete pass, I: Incomplete pass, S: Quarterback sack, IN: Intercepted pass, R: Scramble)|\n|**kickLength**|Kick length in air of kickoff, field goal or punt|\n|**kickReturnYardage**|Yards gained by return team if there was a return on a kickoff or punt|\n|**playResult**|Net yards gained by the kicking team, including penalty yardage|\n|**absoluteYardlineNumber**|Location of ball downfield in tracking data coordinates|\n","metadata":{}},{"cell_type":"code","source":"df_plays = pd.read_csv('../input/nfl-big-data-bowl-2022/plays.csv')","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:50:55.204247Z","iopub.execute_input":"2021-10-12T14:50:55.205266Z","iopub.status.idle":"2021-10-12T14:50:55.355667Z","shell.execute_reply.started":"2021-10-12T14:50:55.205233Z","shell.execute_reply":"2021-10-12T14:50:55.354676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_plays.shape","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:51:36.558276Z","iopub.execute_input":"2021-10-12T14:51:36.558634Z","iopub.status.idle":"2021-10-12T14:51:36.566848Z","shell.execute_reply.started":"2021-10-12T14:51:36.558600Z","shell.execute_reply":"2021-10-12T14:51:36.565906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_plays.info()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:51:46.206846Z","iopub.execute_input":"2021-10-12T14:51:46.207300Z","iopub.status.idle":"2021-10-12T14:51:46.239649Z","shell.execute_reply.started":"2021-10-12T14:51:46.207269Z","shell.execute_reply":"2021-10-12T14:51:46.238572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_plays.describe(include='all')","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:52:02.656946Z","iopub.execute_input":"2021-10-12T14:52:02.657278Z","iopub.status.idle":"2021-10-12T14:52:02.786188Z","shell.execute_reply.started":"2021-10-12T14:52:02.657246Z","shell.execute_reply":"2021-10-12T14:52:02.785139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Too much of null values in **Penalty codes, penaltyJerseyNumbers, penaltyYards, passResult, kickReturnYardage** columns","metadata":{}},{"cell_type":"code","source":"df_plays.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:52:33.012522Z","iopub.execute_input":"2021-10-12T14:52:33.013306Z","iopub.status.idle":"2021-10-12T14:52:33.043332Z","shell.execute_reply.started":"2021-10-12T14:52:33.013240Z","shell.execute_reply":"2021-10-12T14:52:33.042174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Which is the highest scoring quarter in NFL?**","metadata":{}},{"cell_type":"code","source":"df_plays['quarter'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:58:55.181282Z","iopub.execute_input":"2021-10-12T14:58:55.181699Z","iopub.status.idle":"2021-10-12T14:58:55.194246Z","shell.execute_reply.started":"2021-10-12T14:58:55.181661Z","shell.execute_reply":"2021-10-12T14:58:55.192721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**A quarter in football is the main unit of time measurement for the game. The game of football is played in four quarters, each with a 15 minute game clock.**","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nlabels = ['1','2','3','4','5']\nsizes =[4781,5661,4724,4711,102]\ncolors = ['gold','lightskyblue', 'green', 'blue', 'pink']\nexplode = (0,0,0,0,0.1)  \n\nplt.figure(figsize=(14,7))\nplt.pie(sizes, explode=explode, labels=labels, colors=colors, \n        autopct='%1.1f%%', shadow=True, startangle=140)\n\nplt.axis('equal')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T14:59:09.554711Z","iopub.execute_input":"2021-10-12T14:59:09.555732Z","iopub.status.idle":"2021-10-12T14:59:09.713061Z","shell.execute_reply.started":"2021-10-12T14:59:09.555696Z","shell.execute_reply":"2021-10-12T14:59:09.712191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**After the chess match that is the first quarter of an NFL game, it's time for the action to start in the second quarter. This is typically the highest scoring quarter of the game and the one where one team may start to pull away.**","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"**How many plays downs to get a 1st down?**","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(14,7))\nsns.distplot(df_plays['down'], color='r')","metadata":{"execution":{"iopub.status.busy":"2021-10-12T15:12:57.385880Z","iopub.execute_input":"2021-10-12T15:12:57.387138Z","iopub.status.idle":"2021-10-12T15:12:57.860977Z","shell.execute_reply.started":"2021-10-12T15:12:57.387095Z","shell.execute_reply":"2021-10-12T15:12:57.859938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"A team's offense is given **four downs** (plays) to move ten yards toward the opponent's end zone.","metadata":{}},{"cell_type":"markdown","source":"**How many yards to go to get a first down in the NFL?**","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(14,7))\nsns.countplot(data=df_plays, x=df_plays['yardsToGo'])","metadata":{"execution":{"iopub.status.busy":"2021-10-12T15:17:35.139651Z","iopub.execute_input":"2021-10-12T15:17:35.140006Z","iopub.status.idle":"2021-10-12T15:17:35.880196Z","shell.execute_reply.started":"2021-10-12T15:17:35.139974Z","shell.execute_reply":"2021-10-12T15:17:35.879214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Each time the offense gets the ball, it has four downs,which gains 10 yards. If the offensive team successfully moves the ball 10 or more yards, it earns a first down, and another set of four downs. If the offense fails to gain 10 yards, it loses possession of the ball.**","metadata":{}},{"cell_type":"markdown","source":"**Home VS Visitor Score**","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(15,7))\nsns.distplot(df_plays['preSnapHomeScore'], color='g')","metadata":{"execution":{"iopub.status.busy":"2021-10-12T15:33:19.736358Z","iopub.execute_input":"2021-10-12T15:33:19.736928Z","iopub.status.idle":"2021-10-12T15:33:20.268303Z","shell.execute_reply.started":"2021-10-12T15:33:19.736890Z","shell.execute_reply":"2021-10-12T15:33:20.267576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,7))\nsns.distplot(df_plays['preSnapVisitorScore'], color='b')","metadata":{"execution":{"iopub.status.busy":"2021-10-12T15:34:12.059467Z","iopub.execute_input":"2021-10-12T15:34:12.059936Z","iopub.status.idle":"2021-10-12T15:34:12.596643Z","shell.execute_reply.started":"2021-10-12T15:34:12.059904Z","shell.execute_reply":"2021-10-12T15:34:12.595610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,7))\nsns.distplot(df_plays['playResult'], bins= 15, color='y')","metadata":{"execution":{"iopub.status.busy":"2021-10-12T15:37:09.670811Z","iopub.execute_input":"2021-10-12T15:37:09.671173Z","iopub.status.idle":"2021-10-12T15:37:10.143353Z","shell.execute_reply.started":"2021-10-12T15:37:09.671141Z","shell.execute_reply":"2021-10-12T15:37:10.142602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}}]}