{"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-12-16T18:10:37.682719Z","iopub.execute_input":"2021-12-16T18:10:37.683102Z","iopub.status.idle":"2021-12-16T18:10:37.705772Z","shell.execute_reply.started":"2021-12-16T18:10:37.683002Z","shell.execute_reply":"2021-12-16T18:10:37.704443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# analysis of kaggle data science compettition - National Football League\n# https://www.kaggle.com/c/nfl-big-data-bowl-2020/data\n# first we import libraries\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport datetime\nimport os\nimport sys\nimport warnings\nwarnings.filterwarnings('ignore')\nimport matplotlib.cm as cm\nfrom  matplotlib.colors import rgb2hex\nfrom matplotlib.colors import Normalize\nimport matplotlib as mpl\nplt.style.use('fivethirtyeight')","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:37.708569Z","iopub.execute_input":"2021-12-16T18:10:37.709179Z","iopub.status.idle":"2021-12-16T18:10:38.189864Z","shell.execute_reply.started":"2021-12-16T18:10:37.709135Z","shell.execute_reply":"2021-12-16T18:10:38.18852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# #  **Players Data**","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"players = pd.read_csv(\"../input/nfl-big-data-bowl-2022/players.csv\")","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:38.191587Z","iopub.execute_input":"2021-12-16T18:10:38.19196Z","iopub.status.idle":"2021-12-16T18:10:38.207022Z","shell.execute_reply.started":"2021-12-16T18:10:38.191914Z","shell.execute_reply":"2021-12-16T18:10:38.206009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players.head(n=5)","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:38.2103Z","iopub.execute_input":"2021-12-16T18:10:38.21063Z","iopub.status.idle":"2021-12-16T18:10:38.23362Z","shell.execute_reply.started":"2021-12-16T18:10:38.210583Z","shell.execute_reply":"2021-12-16T18:10:38.232719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# players data description\nplayers.describe()\nplayers.info()\nplayers.shape \nplayers.columns\nplayers.dtypes\nplayers.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:38.23533Z","iopub.execute_input":"2021-12-16T18:10:38.236851Z","iopub.status.idle":"2021-12-16T18:10:38.269809Z","shell.execute_reply.started":"2021-12-16T18:10:38.236804Z","shell.execute_reply":"2021-12-16T18:10:38.268709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players[\"birthYear\"] = 0\nplayers[\"birthMonth\"] = 0\n#There are NA values in birthDate so that we should drop them\nplayers.dropna(subset=[\"birthDate\"], inplace=True)\nfor idx, row in players.iterrows():\n    if len(row['birthDate'].split('/')) == 3: # 05/17/1994 \n        players.loc[idx, 'birthYear'] = row['birthDate'].split('/')[2]\n        players.loc[idx, 'birthMonth'] = row['birthDate'].split('/')[0]\n        \n    elif len(row['birthDate'].split('-')) == 3: # 1995-05-05\n        players.loc[idx, 'birthYear'] = row['birthDate'].split('-')[0]\n        players.loc[idx, 'birthMonth'] = row['birthDate'].split('-')[1]","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:38.271654Z","iopub.execute_input":"2021-12-16T18:10:38.272431Z","iopub.status.idle":"2021-12-16T18:10:40.452383Z","shell.execute_reply.started":"2021-12-16T18:10:38.272384Z","shell.execute_reply":"2021-12-16T18:10:40.451289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:40.454986Z","iopub.execute_input":"2021-12-16T18:10:40.455504Z","iopub.status.idle":"2021-12-16T18:10:40.46945Z","shell.execute_reply.started":"2021-12-16T18:10:40.455455Z","shell.execute_reply":"2021-12-16T18:10:40.46842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players.tail(n=5)","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:40.471193Z","iopub.execute_input":"2021-12-16T18:10:40.471877Z","iopub.status.idle":"2021-12-16T18:10:40.492515Z","shell.execute_reply.started":"2021-12-16T18:10:40.471831Z","shell.execute_reply":"2021-12-16T18:10:40.491275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:40.494977Z","iopub.execute_input":"2021-12-16T18:10:40.495492Z","iopub.status.idle":"2021-12-16T18:10:40.515902Z","shell.execute_reply.started":"2021-12-16T18:10:40.495446Z","shell.execute_reply":"2021-12-16T18:10:40.514792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# lets create a new column for age\nplayers['age'] = 0\nfor idx, row in players.iterrows():\n    players.loc[idx, 'age'] = 2020 - int(row['birthYear'])","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:40.520929Z","iopub.execute_input":"2021-12-16T18:10:40.52144Z","iopub.status.idle":"2021-12-16T18:10:41.552277Z","shell.execute_reply.started":"2021-12-16T18:10:40.521394Z","shell.execute_reply":"2021-12-16T18:10:41.551278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:41.555046Z","iopub.execute_input":"2021-12-16T18:10:41.555605Z","iopub.status.idle":"2021-12-16T18:10:41.574366Z","shell.execute_reply.started":"2021-12-16T18:10:41.555557Z","shell.execute_reply":"2021-12-16T18:10:41.57336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# convert heights to cm and weights to kg\nplayers_heights = players[\"height\"] # Get the Height data from DataFrame\nplayers_heights = players_heights.apply(lambda x: x.split(\"-\")) # Split the heights by hyphen (\"-\")\n\n# Convert Heights to Centimeters and add them to DataFrame\nplayers[\"height\"] = players_heights.apply(lambda x: int(x[0]) * 12 + int(x[1]) if len(x) == 2 else int(x[0])) * 2.54\n\n# Convert Weights to Kilograms and them to DataFrame\nplayers[\"weight\"] = round(players.weight * 0.453592, 2)\n\n","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:41.575953Z","iopub.execute_input":"2021-12-16T18:10:41.57627Z","iopub.status.idle":"2021-12-16T18:10:41.593912Z","shell.execute_reply.started":"2021-12-16T18:10:41.576222Z","shell.execute_reply":"2021-12-16T18:10:41.59299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:41.595613Z","iopub.execute_input":"2021-12-16T18:10:41.596161Z","iopub.status.idle":"2021-12-16T18:10:41.623821Z","shell.execute_reply.started":"2021-12-16T18:10:41.596114Z","shell.execute_reply":"2021-12-16T18:10:41.622707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:41.625362Z","iopub.execute_input":"2021-12-16T18:10:41.625844Z","iopub.status.idle":"2021-12-16T18:10:41.653841Z","shell.execute_reply.started":"2021-12-16T18:10:41.625739Z","shell.execute_reply":"2021-12-16T18:10:41.652764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#height distribution plot \nsns.set_style('whitegrid')\nsns.set_context('notebook', font_scale=1.5, rc={\"lines.linewidth\": 2.5})\n\nfig = plt.figure(figsize=(10, 6))\nax = fig.add_subplot(111)\nax.set_title('Players Height Distribution')\nax.set_xlabel('Height')\nax.set_ylabel('Frequency')\n\nplayers.height.hist(bins=50, ax=ax)\nplt.show();\n","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:41.655279Z","iopub.execute_input":"2021-12-16T18:10:41.656518Z","iopub.status.idle":"2021-12-16T18:10:42.121452Z","shell.execute_reply.started":"2021-12-16T18:10:41.656469Z","shell.execute_reply":"2021-12-16T18:10:42.120511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# weight distribution plot \nsns.set_style('whitegrid')\nsns.set_context('notebook', font_scale=1.5, rc={\"lines.linewidth\": 2.5})\n\nfig = plt.figure(figsize=(10, 6))\nax = fig.add_subplot(111)\nax.set_title('Players Weight Distribution')\nax.set_xlabel('Weight')\nax.set_ylabel('Frequency')\n\nplayers.weight.hist(bins=50, ax=ax)\nplt.show();","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:42.122952Z","iopub.execute_input":"2021-12-16T18:10:42.124069Z","iopub.status.idle":"2021-12-16T18:10:42.554303Z","shell.execute_reply.started":"2021-12-16T18:10:42.12402Z","shell.execute_reply":"2021-12-16T18:10:42.553251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Visualization of the players data \n# position vs height\nsns.set_style('whitegrid')\nsns.set_context('notebook', font_scale=1.5, rc={\"lines.linewidth\": 2.5})\n\nfig = plt.figure(figsize=(10, 6))\nax = fig.add_subplot(111)\nax.set_title('Players Height vs Position')\nax.set_xlabel('Height in cm')\nax.set_ylabel('Position')\nax.set_ylim(0, 100)\n\nplayers.height.hist(bins=50, ax=ax)\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:42.556163Z","iopub.execute_input":"2021-12-16T18:10:42.556743Z","iopub.status.idle":"2021-12-16T18:10:42.99457Z","shell.execute_reply.started":"2021-12-16T18:10:42.556661Z","shell.execute_reply":"2021-12-16T18:10:42.993604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# position vs weight\nsns.set_style('whitegrid')\nsns.set_context('notebook', font_scale=1.5, rc={\"lines.linewidth\": 2.5})\n\nfig = plt.figure(figsize=(10, 6))\nax = fig.add_subplot(111)\nax.set_title('Players Weight vs Position')\nax.set_xlabel('Weight in kg')\nax.set_ylabel('Position')\nax.set_ylim(0, 100)\n\nplayers.weight.hist(bins=50, ax=ax)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:42.996512Z","iopub.execute_input":"2021-12-16T18:10:42.9971Z","iopub.status.idle":"2021-12-16T18:10:43.574819Z","shell.execute_reply.started":"2021-12-16T18:10:42.997039Z","shell.execute_reply":"2021-12-16T18:10:43.573905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# top 10 Position played by players\ntop_10 = players.groupby(['Position'])['Position'].count().sort_values(ascending=False).head(10)\ntop_10.plot(kind='bar', figsize=(10, 6))\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:43.579991Z","iopub.execute_input":"2021-12-16T18:10:43.582463Z","iopub.status.idle":"2021-12-16T18:10:44.085384Z","shell.execute_reply.started":"2021-12-16T18:10:43.582418Z","shell.execute_reply":"2021-12-16T18:10:44.084518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# player height vs weight\nsns.set_style('whitegrid')\nsns.set_context('notebook', font_scale=1.5, rc={\"lines.linewidth\": 2.5})\nsns.regplot(x='weight', y='height', data=players, fit_reg=False, scatter_kws={'s': 80})\nplt.show();","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:44.086721Z","iopub.execute_input":"2021-12-16T18:10:44.087155Z","iopub.status.idle":"2021-12-16T18:10:44.492896Z","shell.execute_reply.started":"2021-12-16T18:10:44.087112Z","shell.execute_reply":"2021-12-16T18:10:44.492022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# college with most players (Top 10 college team)  visualization\n# top 10 college team\ntop_10 = players.groupby(['collegeName'])['collegeName'].count().sort_values(ascending=False).head(10)\ntop_10.plot(kind='bar', figsize=(10, 6))\nplt.show();\n","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:44.494418Z","iopub.execute_input":"2021-12-16T18:10:44.495459Z","iopub.status.idle":"2021-12-16T18:10:45.0806Z","shell.execute_reply.started":"2021-12-16T18:10:44.495416Z","shell.execute_reply":"2021-12-16T18:10:45.079766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#players count with age visualization\nsns.set_style('whitegrid')\nsns.set_context('notebook', font_scale=1.5, rc={\"lines.linewidth\": 2.5})\n\nfig = plt.figure(figsize=(10, 6))\nax = fig.add_subplot(111)\nax.set_title('Players Age vs Position')\nax.set_xlabel('Age')\nax.set_ylabel('Position')\nax.set_ylim(0, 100)\n\nplayers.age.hist(bins=50, ax=ax)\nplt.show();","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:45.08231Z","iopub.execute_input":"2021-12-16T18:10:45.082985Z","iopub.status.idle":"2021-12-16T18:10:45.683604Z","shell.execute_reply.started":"2021-12-16T18:10:45.082939Z","shell.execute_reply":"2021-12-16T18:10:45.681787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# players birth year distribution plot with sns displot\nmpl.rc('font', size=15) \nplt.figure(figsize=(10, 5))\n\nax = sns.distplot(players['birthYear'], bins=25)\nax.set_title('Players birth year Distribution');","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:45.685598Z","iopub.execute_input":"2021-12-16T18:10:45.68614Z","iopub.status.idle":"2021-12-16T18:10:46.141787Z","shell.execute_reply.started":"2021-12-16T18:10:45.686091Z","shell.execute_reply":"2021-12-16T18:10:46.140664Z"}}},{"cell_type":"markdown","source":"# # ****Games Data****","metadata":{}},{"cell_type":"code","source":"# games data \ngames = pd.read_csv('../input/nfl-big-data-bowl-2022/games.csv')","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:46.143656Z","iopub.execute_input":"2021-12-16T18:10:46.144076Z","iopub.status.idle":"2021-12-16T18:10:46.155848Z","shell.execute_reply.started":"2021-12-16T18:10:46.14403Z","shell.execute_reply":"2021-12-16T18:10:46.154828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games.head(n=5)","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:46.157812Z","iopub.execute_input":"2021-12-16T18:10:46.158255Z","iopub.status.idle":"2021-12-16T18:10:46.172443Z","shell.execute_reply.started":"2021-12-16T18:10:46.15821Z","shell.execute_reply":"2021-12-16T18:10:46.171382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#games data description\ngames.describe()\ngames.info()\ngames.shape\ngames.columns\ngames.dtypes\ngames.isnull().sum()\ngames.isnull().sum().sum()","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:46.174186Z","iopub.execute_input":"2021-12-16T18:10:46.174877Z","iopub.status.idle":"2021-12-16T18:10:46.209887Z","shell.execute_reply.started":"2021-12-16T18:10:46.17483Z","shell.execute_reply":"2021-12-16T18:10:46.208756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# add column month of year and day of week\ngames['month'] = pd.to_datetime(games['gameDate']).dt.month_name()\ngames['day_of_week'] = pd.to_datetime(games['gameDate']).dt.day_name()\ngames['day'] = games['gameDate'].apply(lambda x: int(x.split('/')[1]))\ngames.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:46.211734Z","iopub.execute_input":"2021-12-16T18:10:46.212288Z","iopub.status.idle":"2021-12-16T18:10:46.242843Z","shell.execute_reply.started":"2021-12-16T18:10:46.212241Z","shell.execute_reply":"2021-12-16T18:10:46.240757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#writing function for perentage  at the top of bar \ndef write_percentage(ax,total_size):\n    for p in ax.patches:\n        x=p.get_x()+p.get_width()/2\n        y=p.get_y()+p.get_height()\n        val=int(p.get_height()/total_size*100)\n        ax.annotate('{}%'.format(val), (x,y), ha='center', va='bottom', fontsize=10)","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:46.249436Z","iopub.execute_input":"2021-12-16T18:10:46.249729Z","iopub.status.idle":"2021-12-16T18:10:46.256399Z","shell.execute_reply.started":"2021-12-16T18:10:46.249671Z","shell.execute_reply":"2021-12-16T18:10:46.255269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" #games data visulaization count per season with perentage at top of bar \nsns.set_style('whitegrid')\nsns.set_context('notebook', font_scale=1.5, rc={\"lines.linewidth\": 2.5})\nwrite_percentage(sns.countplot(x='season', data=games , palette='Set2', order=games.season.unique()),games.season.count())","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:46.258533Z","iopub.execute_input":"2021-12-16T18:10:46.259314Z","iopub.status.idle":"2021-12-16T18:10:46.520028Z","shell.execute_reply.started":"2021-12-16T18:10:46.259257Z","shell.execute_reply":"2021-12-16T18:10:46.519061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# games data visulaization Number of games per month with percentage at top of bar \nmpl.rc('font', size=15)\nplt.figure(figsize=(8, 6))\nax=(sns.countplot(x='month', data=games , palette='Set2', order=games.month.unique()))\nwrite_percentage(ax,games.month.count())\nax.set_title('Number of games per month')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:46.521725Z","iopub.execute_input":"2021-12-16T18:10:46.522249Z","iopub.status.idle":"2021-12-16T18:10:46.791596Z","shell.execute_reply.started":"2021-12-16T18:10:46.522204Z","shell.execute_reply":"2021-12-16T18:10:46.790617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#games data visulaization Number of games per day with percentage at top of bar with title number of games per day\nmpl.rc('font', size=15)\nplt.figure(figsize=(8, 6))\nax= sns.countplot(x='day_of_week', data=games , palette='Set2', order=games.day_of_week.unique())\nwrite_percentage(ax,games.day_of_week.count())\nax.set_title('Number of games per day')\nplt.show();","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:46.793096Z","iopub.execute_input":"2021-12-16T18:10:46.793788Z","iopub.status.idle":"2021-12-16T18:10:47.110499Z","shell.execute_reply.started":"2021-12-16T18:10:46.79373Z","shell.execute_reply":"2021-12-16T18:10:47.109548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# games data visulaization count per week\nsns.set_style('whitegrid')\nsns.set_context('notebook', font_scale=1.5, rc={\"lines.linewidth\": 2.5})\nsns.countplot(x='week', data=games , palette='Set2', order=games.week.unique())\nplt.show();","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:47.112248Z","iopub.execute_input":"2021-12-16T18:10:47.112523Z","iopub.status.idle":"2021-12-16T18:10:47.491219Z","shell.execute_reply.started":"2021-12-16T18:10:47.112488Z","shell.execute_reply":"2021-12-16T18:10:47.490293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Number of games per day with percentage at top of bar with title number of games per day\nmpl.rc('figure', figsize=(10, 6))\nplt.figure(figsize=(15, 7))\nax =sns.countplot(x='day', data=games , palette='Set2', order=games.day.unique())\nwrite_percentage(ax,games.day.count())\nax.set_title('Number of games per day')\nplt.show();","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:47.492649Z","iopub.execute_input":"2021-12-16T18:10:47.493533Z","iopub.status.idle":"2021-12-16T18:10:48.268551Z","shell.execute_reply.started":"2021-12-16T18:10:47.493487Z","shell.execute_reply":"2021-12-16T18:10:48.2676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Number of games for gameTimeEastern and gameTimeLocal in ascending order with percentage at top of bar with title number of games per gameTimeEastern\nmpl.rc('figure', figsize=(10, 6))\nplt.figure(figsize=(15, 7))\nax=sns.countplot(x='gameTimeEastern', data=games , palette='Set2', order=games.gameTimeEastern.unique())\nwrite_percentage(ax,games.gameTimeEastern.count())\nax.set_title('Number of games per gameTimeEastern')\nax.tick_params('x', labelrotation=30)\nplt.show();","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:48.269981Z","iopub.execute_input":"2021-12-16T18:10:48.270915Z","iopub.status.idle":"2021-12-16T18:10:48.779196Z","shell.execute_reply.started":"2021-12-16T18:10:48.270839Z","shell.execute_reply":"2021-12-16T18:10:48.778264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Plotting Number of Games played in each month for each season\nsns.set_style('whitegrid')\nsns.set_context('notebook', font_scale=1.5, rc={\"lines.linewidth\": 2.5})\n\nfig = plt.figure(figsize=(10, 6))\nax = fig.add_subplot(111)\nbox = ax.get_position()\nax.set_position([box.x0, box.y0, box.width * 2, box.height * 2])\n\nax.set_title('Number of Games played in each month for each season')\nax.set_xlabel('Season')\nax.set_ylabel('Number of Games')\n\nax=sns.countplot(x='season', hue='month', data=games, palette='Set2', order=games.season.unique())\n\nplt.show();","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:48.780878Z","iopub.execute_input":"2021-12-16T18:10:48.781422Z","iopub.status.idle":"2021-12-16T18:10:49.154572Z","shell.execute_reply.started":"2021-12-16T18:10:48.781373Z","shell.execute_reply":"2021-12-16T18:10:49.153601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# # ****Plays Data info**** ","metadata":{}},{"cell_type":"code","source":"plays= pd.read_csv(\"../input/nfl-big-data-bowl-2022/plays.csv\")","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:49.156246Z","iopub.execute_input":"2021-12-16T18:10:49.156811Z","iopub.status.idle":"2021-12-16T18:10:49.246187Z","shell.execute_reply.started":"2021-12-16T18:10:49.156763Z","shell.execute_reply":"2021-12-16T18:10:49.245189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plays.head(n=5)","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:49.247938Z","iopub.execute_input":"2021-12-16T18:10:49.248282Z","iopub.status.idle":"2021-12-16T18:10:49.283711Z","shell.execute_reply.started":"2021-12-16T18:10:49.248237Z","shell.execute_reply":"2021-12-16T18:10:49.282453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plays.info()\nplays.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:49.285556Z","iopub.execute_input":"2021-12-16T18:10:49.286656Z","iopub.status.idle":"2021-12-16T18:10:49.34739Z","shell.execute_reply.started":"2021-12-16T18:10:49.286601Z","shell.execute_reply":"2021-12-16T18:10:49.346182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plays['specialTeamsPlayType'].value_counts().to_frame()","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:49.349051Z","iopub.execute_input":"2021-12-16T18:10:49.349483Z","iopub.status.idle":"2021-12-16T18:10:49.364172Z","shell.execute_reply.started":"2021-12-16T18:10:49.349435Z","shell.execute_reply":"2021-12-16T18:10:49.363095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plays data visulaization count per quarter\nsns.set_style('whitegrid')\nsns.set_context('notebook', font_scale=1.5, rc={\"lines.linewidth\": 2.5})\nsns.countplot(x='quarter', data=plays , palette='Set2', order=plays.quarter.unique())\nplt.show();","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:49.366142Z","iopub.execute_input":"2021-12-16T18:10:49.367464Z","iopub.status.idle":"2021-12-16T18:10:49.618159Z","shell.execute_reply.started":"2021-12-16T18:10:49.367417Z","shell.execute_reply":"2021-12-16T18:10:49.617125Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#play result distribution for each quarter with bar plot\nmpl.rc('font', size=15) \nplt.figure(figsize=(10, 5))\nsns.countplot(x='playResult', hue='quarter', data=plays , palette='Set2', order=plays.quarter.unique())\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:49.619563Z","iopub.execute_input":"2021-12-16T18:10:49.620523Z","iopub.status.idle":"2021-12-16T18:10:49.996915Z","shell.execute_reply.started":"2021-12-16T18:10:49.620476Z","shell.execute_reply":"2021-12-16T18:10:49.995944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#preSnapHomeScore with distribution plot with bins=12\nsns.set_style('whitegrid')\nsns.set_context('notebook', font_scale=1.5, rc={\"lines.linewidth\": 2.5})\nsns.distplot(plays.preSnapHomeScore, bins=12)\nplt.show();\n","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:49.998561Z","iopub.execute_input":"2021-12-16T18:10:49.999146Z","iopub.status.idle":"2021-12-16T18:10:50.474663Z","shell.execute_reply.started":"2021-12-16T18:10:49.999096Z","shell.execute_reply":"2021-12-16T18:10:50.47376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Number of plays with down \nsns.set_style('whitegrid')\nsns.set_context('notebook', font_scale=1.5, rc={\"lines.linewidth\": 2.5})\n\nsns.countplot(x='down', data=plays , palette='Set2', order=plays.down.unique())\nplt.show();","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:50.476266Z","iopub.execute_input":"2021-12-16T18:10:50.477138Z","iopub.status.idle":"2021-12-16T18:10:50.725748Z","shell.execute_reply.started":"2021-12-16T18:10:50.477091Z","shell.execute_reply":"2021-12-16T18:10:50.724745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Number of plays with yardsToGo\nmpl.rc('font', size=12) \nplt.figure(figsize=(12, 6))\n\nax = sns.countplot(x='yardsToGo', data=plays)\nax.set_title('Number of plays for every yards to go category');","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:50.72763Z","iopub.execute_input":"2021-12-16T18:10:50.728244Z","iopub.status.idle":"2021-12-16T18:10:51.610107Z","shell.execute_reply.started":"2021-12-16T18:10:50.728197Z","shell.execute_reply":"2021-12-16T18:10:51.609102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#                      Tracking Data****","metadata":{}},{"cell_type":"code","source":"tracking2020 = pd.read_csv(\"../input/nfl-big-data-bowl-2022/tracking2020.csv\")","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:10:51.611883Z","iopub.execute_input":"2021-12-16T18:10:51.612404Z","iopub.status.idle":"2021-12-16T18:11:19.545814Z","shell.execute_reply.started":"2021-12-16T18:10:51.612344Z","shell.execute_reply":"2021-12-16T18:11:19.544786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tracking2020.head(n=5)","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:11:19.547568Z","iopub.execute_input":"2021-12-16T18:11:19.547901Z","iopub.status.idle":"2021-12-16T18:11:19.580061Z","shell.execute_reply.started":"2021-12-16T18:11:19.54786Z","shell.execute_reply":"2021-12-16T18:11:19.578912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tracking2020.info()\ntracking2020.describe()\ntracking2020.shape\ntracking2020.columns\ntracking2020.dtypes\ntracking2020.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:11:19.581873Z","iopub.execute_input":"2021-12-16T18:11:19.582241Z","iopub.status.idle":"2021-12-16T18:11:30.473672Z","shell.execute_reply.started":"2021-12-16T18:11:19.582167Z","shell.execute_reply":"2021-12-16T18:11:30.472651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(12, 8))\ntracking2020.query('gameId == 2021010300 and playId == 40').groupby('team') \\\n    .plot(x='x', y='y', ax=ax, style='.')\nplt.legend().remove();","metadata":{"execution":{"iopub.status.busy":"2021-12-16T18:12:27.370392Z","iopub.execute_input":"2021-12-16T18:12:27.370702Z","iopub.status.idle":"2021-12-16T18:12:27.82297Z","shell.execute_reply.started":"2021-12-16T18:12:27.370651Z","shell.execute_reply":"2021-12-16T18:12:27.821896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}