{"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","_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2021-12-23T18:23:45.028162Z","iopub.execute_input":"2021-12-23T18:23:45.028875Z","iopub.status.idle":"2021-12-23T18:23:45.048021Z","shell.execute_reply.started":"2021-12-23T18:23:45.028770Z","shell.execute_reply":"2021-12-23T18:23:45.046889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <p style=\"text-align:center;\"> ✨🏈 NFL Big Data Bowl - EDA 🏈✨  </p>","metadata":{}},{"cell_type":"markdown","source":"<div style=\"width:100%;text-align: center;\"> <img align=middle src=\"https://cloudfront-us-east-1.images.arcpublishing.com/gray/42TKT722XJLFPFT45YL2PPSFS4.jpg\" alt=\"Heat beating\" style=\"height:300px;margin-top:3rem;\">!</div>","metadata":{}},{"cell_type":"markdown","source":"**<p style=\"text-align:center;\"> Beginner-friendly EDA notebook. More analyses and visualizations are on the way for future updates !! </p>**","metadata":{}},{"cell_type":"markdown","source":"# Upvote is Free 😇","metadata":{}},{"cell_type":"markdown","source":"**PLEASE UPVOTE if you like this EDA notebook.  It will keep me inspired to update my notebook.**","metadata":{}},{"cell_type":"markdown","source":"# IMPORTING LIBRARIES","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nfrom matplotlib import pyplot as plt \nimport matplotlib.patches as patches\nimport plotly.express as px\nimport plotly.graph_objects as pg\nfrom plotly import tools as tls","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:45.051017Z","iopub.execute_input":"2021-12-23T18:23:45.051408Z","iopub.status.idle":"2021-12-23T18:23:45.914382Z","shell.execute_reply.started":"2021-12-23T18:23:45.051358Z","shell.execute_reply":"2021-12-23T18:23:45.913365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <p style=\"text-align:center;\"> ✨1. Player Data✨  </p>","metadata":{}},{"cell_type":"markdown","source":"**Player data:** The players.csv file contains player-level information from players that participated in any of the tracking data files. The key variable is nflId.\n\n* nflId: Player identification number, unique across players (numeric)\n* Height: Player height (text)\n* Weight: Player weight (numeric)\n* birthDate: Date of birth (YYYY-MM-DD)\n* collegeName: Player college (text)\n* Position: Player position (text)\n* displayName: Player name (text)","metadata":{}},{"cell_type":"markdown","source":"# Loading Data","metadata":{}},{"cell_type":"code","source":"player = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/players.csv')\nprint(\"Number of data points:\", len(player))\nprint(\"Number of columns:\", player.shape[1])\nplayer.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:45.915974Z","iopub.execute_input":"2021-12-23T18:23:45.916378Z","iopub.status.idle":"2021-12-23T18:23:45.945737Z","shell.execute_reply.started":"2021-12-23T18:23:45.916338Z","shell.execute_reply":"2021-12-23T18:23:45.944821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Cleaning","metadata":{}},{"cell_type":"markdown","source":"**We want to examine the dataset to know the steps taken to clean the dataset.**","metadata":{}},{"cell_type":"code","source":"# Dataset Summary\nplayer.info()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:45.947353Z","iopub.execute_input":"2021-12-23T18:23:45.947679Z","iopub.status.idle":"2021-12-23T18:23:45.963190Z","shell.execute_reply.started":"2021-12-23T18:23:45.947635Z","shell.execute_reply":"2021-12-23T18:23:45.962285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**From the above output, we can conclude that**\n\n1. The birthDate and collegeName column has missing values.\n\n2. Convert all heights from format feet - inch or inch to feet.\n\n3. The birthDate column should be parsed as DateTime instead of Object.\n\n4. Splitting YYYY (Year) from YYYY-MM-DD date format to calculate birth year of players.\n\n5. Replacing abbrevated words with keywords in Position column.","metadata":{}},{"cell_type":"markdown","source":"# Eliminate Null Values","metadata":{}},{"cell_type":"code","source":"player = player.dropna()\nprint(\"The shape of the dataset after removing null values is : \", player.shape)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:45.965463Z","iopub.execute_input":"2021-12-23T18:23:45.965822Z","iopub.status.idle":"2021-12-23T18:23:45.989629Z","shell.execute_reply.started":"2021-12-23T18:23:45.965782Z","shell.execute_reply":"2021-12-23T18:23:45.988696Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from height column","metadata":{}},{"cell_type":"code","source":"print(\"Unique height values and their counts :\")\nprint(player[\"height\"].value_counts())","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:45.990904Z","iopub.execute_input":"2021-12-23T18:23:45.991163Z","iopub.status.idle":"2021-12-23T18:23:46.001005Z","shell.execute_reply.started":"2021-12-23T18:23:45.991133Z","shell.execute_reply":"2021-12-23T18:23:45.999851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**From the above output, we can conclude that there are two formats in height values.**\n\n1. Feet - Inch ( Ex: 6-3, 6-4 )\n2. Inches ( Ex : 72, 78 )","metadata":{}},{"cell_type":"markdown","source":"# Feature Engineering - Converting all heights to feet","metadata":{}},{"cell_type":"markdown","source":"**Parsing Object as String and splitting height values (Ex: 6-3) into two (Ex: 6 Feet and 3 Inches)**","metadata":{}},{"cell_type":"code","source":"new_height = player[\"height\"].str.split(\"-\", n = 1, expand = True)\nnew_height.columns = ['Feet', 'Inch']\nplayer[\"height_feet\"] = pd.to_numeric(new_height[\"Feet\"])\nplayer[\"height_inch\"] = pd.to_numeric(new_height[\"Inch\"])\nprint(\"The shape of the dataset after feature engineering is : \", player.shape)\nprint(player)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:46.002232Z","iopub.execute_input":"2021-12-23T18:23:46.002488Z","iopub.status.idle":"2021-12-23T18:23:46.036880Z","shell.execute_reply.started":"2021-12-23T18:23:46.002456Z","shell.execute_reply":"2021-12-23T18:23:46.035857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Converting Inches to Feet by multiplying inch value with 0.0833333 (Since 1 inch = 0.0833333 feet)**","metadata":{}},{"cell_type":"code","source":"# Column - height_feet\nfor i in player[\"height_feet\"]:\n    if i > 7:\n        j = 0.0833333 * i\n        player[\"height_feet\"].replace({i : j}, inplace=True)\n        \n# Column - height_inch\nplayer[\"height_inch\"] = 0.0833333 * player[\"height_inch\"]\nprint(player.tail())","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:46.038443Z","iopub.execute_input":"2021-12-23T18:23:46.038767Z","iopub.status.idle":"2021-12-23T18:23:46.090862Z","shell.execute_reply.started":"2021-12-23T18:23:46.038723Z","shell.execute_reply":"2021-12-23T18:23:46.089829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Converting Nan values to zero in height_inch column to perform arithmetic operations**","metadata":{}},{"cell_type":"code","source":"for i in player[\"height_inch\"]:\n    player[\"height_inch\"] = player[\"height_inch\"].fillna(0)\nprint(player[\"height_inch\"])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:46.092276Z","iopub.execute_input":"2021-12-23T18:23:46.092603Z","iopub.status.idle":"2021-12-23T18:23:46.629379Z","shell.execute_reply.started":"2021-12-23T18:23:46.092557Z","shell.execute_reply":"2021-12-23T18:23:46.627572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Now inch values are converted into feet values.**\n**The next step will be getting total feet values by adding height_inch & height_feet column.**","metadata":{}},{"cell_type":"code","source":"player[\"height_feet\"] = player[\"height_feet\"] + player[\"height_inch\"]\nprint(player[\"height_feet\"])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:46.630890Z","iopub.execute_input":"2021-12-23T18:23:46.631311Z","iopub.status.idle":"2021-12-23T18:23:46.639925Z","shell.execute_reply.started":"2021-12-23T18:23:46.631263Z","shell.execute_reply":"2021-12-23T18:23:46.638962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Exploring height_feet Column","metadata":{}},{"cell_type":"code","source":"# Maximum and Minimum height of the players in feet\nprint(\"Maximum height of the player in feet : \",max(player[\"height_feet\"]))\nprint(\"Minimum height of the player in feet : \",min(player[\"height_feet\"]))","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:46.641198Z","iopub.execute_input":"2021-12-23T18:23:46.641434Z","iopub.status.idle":"2021-12-23T18:23:46.651442Z","shell.execute_reply.started":"2021-12-23T18:23:46.641407Z","shell.execute_reply":"2021-12-23T18:23:46.650574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing height_feet column by Histogram","metadata":{}},{"cell_type":"code","source":"# Creating Histogram plot\nfig = px.histogram(player, x=\"height_feet\", title=\"Player's Height In Feet\", nbins=10, color_discrete_sequence=[\"royalblue\"])\n\n# Displaying Histogram plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:46.652451Z","iopub.execute_input":"2021-12-23T18:23:46.653170Z","iopub.status.idle":"2021-12-23T18:23:46.956422Z","shell.execute_reply.started":"2021-12-23T18:23:46.653132Z","shell.execute_reply":"2021-12-23T18:23:46.955599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from weight column","metadata":{}},{"cell_type":"code","source":"print(\"Unique weight values and their counts :\")\nprint(player[\"weight\"].value_counts())","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:46.957738Z","iopub.execute_input":"2021-12-23T18:23:46.957996Z","iopub.status.idle":"2021-12-23T18:23:46.966064Z","shell.execute_reply.started":"2021-12-23T18:23:46.957965Z","shell.execute_reply":"2021-12-23T18:23:46.964872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**From the above output we can conclude that there is no anomaly (something that deviates from what is standard, normal, or expected)  and all weights are in lbs (pounds).**","metadata":{}},{"cell_type":"markdown","source":"# Exploring weight Column","metadata":{}},{"cell_type":"code","source":"# Maximum and Minimum weight of the players in lbs (pounds)\nprint(\"Maximum weight of the player in lbs (pounds) : \",max(player[\"weight\"]))\nprint(\"Minimum weight of the player in lbs (pounds) : \",min(player[\"weight\"]))","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:46.969967Z","iopub.execute_input":"2021-12-23T18:23:46.970359Z","iopub.status.idle":"2021-12-23T18:23:46.980925Z","shell.execute_reply.started":"2021-12-23T18:23:46.970320Z","shell.execute_reply":"2021-12-23T18:23:46.980085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing weight column by Histogram","metadata":{}},{"cell_type":"code","source":"# Creating Histogram plot\nfig = px.histogram(player, x=\"weight\", title=\"Player's Weight In lbs (pounds)\", color_discrete_sequence=[\"darkblue\"])\n\n# Displaying Histogram plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:46.982247Z","iopub.execute_input":"2021-12-23T18:23:46.982576Z","iopub.status.idle":"2021-12-23T18:23:47.065096Z","shell.execute_reply.started":"2021-12-23T18:23:46.982542Z","shell.execute_reply":"2021-12-23T18:23:47.063995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Feature Engineering - Converting YYYY-MM-DD date format to YYYY (year) format","metadata":{}},{"cell_type":"markdown","source":"**Parsing Object as DateTime**","metadata":{}},{"cell_type":"code","source":"print(\"Data type of birthDate column before parsing : \", player[\"birthDate\"].dtypes)\nplayer[\"birthDate\"] = pd.to_datetime(player[\"birthDate\"])\nprint(\"Data type of birthDate column after parsing : \", player[\"birthDate\"].dtypes)\nprint(player[\"birthDate\"].head())","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:47.066438Z","iopub.execute_input":"2021-12-23T18:23:47.066687Z","iopub.status.idle":"2021-12-23T18:23:47.079260Z","shell.execute_reply.started":"2021-12-23T18:23:47.066656Z","shell.execute_reply":"2021-12-23T18:23:47.078315Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Splitting YYYY (Year) from YYYY-MM-DD date format**","metadata":{}},{"cell_type":"code","source":"player['birthYear'] = pd.DatetimeIndex(player['birthDate']).year\nprint(player[\"birthYear\"])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:47.080928Z","iopub.execute_input":"2021-12-23T18:23:47.081293Z","iopub.status.idle":"2021-12-23T18:23:47.097781Z","shell.execute_reply.started":"2021-12-23T18:23:47.081247Z","shell.execute_reply":"2021-12-23T18:23:47.097100Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from birthYear column","metadata":{}},{"cell_type":"code","source":"print(\"Unique birth year values and their counts :\")\nprint(player[\"birthYear\"].value_counts())","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:47.099114Z","iopub.execute_input":"2021-12-23T18:23:47.099640Z","iopub.status.idle":"2021-12-23T18:23:47.110216Z","shell.execute_reply.started":"2021-12-23T18:23:47.099604Z","shell.execute_reply":"2021-12-23T18:23:47.109228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**From the above output we can conclude that there is no anomaly (something that deviates from what is standard, normal, or expected)  and all date values are in YYYY format.**","metadata":{}},{"cell_type":"markdown","source":"# Exploring birthYear Column","metadata":{}},{"cell_type":"code","source":"# Newest and oldest player\nprint(\"Newest player birth year : \",max(player[\"birthYear\"]))\nprint(\"Oldest player birth year : \",min(player[\"birthYear\"]))","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:47.112023Z","iopub.execute_input":"2021-12-23T18:23:47.112541Z","iopub.status.idle":"2021-12-23T18:23:47.120910Z","shell.execute_reply.started":"2021-12-23T18:23:47.112509Z","shell.execute_reply":"2021-12-23T18:23:47.120077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing birthYear column by Histogram","metadata":{}},{"cell_type":"code","source":"# Creating Histogram plot\nfig = px.histogram(player, x=\"birthYear\", title=\"Birth Year Of Players\", color_discrete_sequence=[\"red\"])\n\n# Displaying Histogram plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:47.122151Z","iopub.execute_input":"2021-12-23T18:23:47.122394Z","iopub.status.idle":"2021-12-23T18:23:47.338116Z","shell.execute_reply.started":"2021-12-23T18:23:47.122357Z","shell.execute_reply":"2021-12-23T18:23:47.337006Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from collegeName column","metadata":{}},{"cell_type":"code","source":"print(\"Unique college names and their counts : \")\ncollege_names = player.pivot_table(index = ['collegeName'], aggfunc = 'size') \ncollege_names = college_names.reset_index()\ncollege_names.columns= [\"College Names\", \"Counts\"]\ncollege_names = college_names.sort_values(\"Counts\", ascending = False)\nprint(college_names)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:47.339311Z","iopub.execute_input":"2021-12-23T18:23:47.339537Z","iopub.status.idle":"2021-12-23T18:23:47.354674Z","shell.execute_reply.started":"2021-12-23T18:23:47.339510Z","shell.execute_reply":"2021-12-23T18:23:47.353729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing arrangement of colleges from highest to lowest number of players  by Treemap plot","metadata":{}},{"cell_type":"code","source":"# Creating Treemap plot\nfig = px.treemap(college_names, path=['College Names'], values='Counts', color='Counts', title=\"Arrangement Of Colleges From Highest To Lowest Number Of Players\")\n\n# Displaying Treemap plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:47.355883Z","iopub.execute_input":"2021-12-23T18:23:47.356145Z","iopub.status.idle":"2021-12-23T18:23:47.581184Z","shell.execute_reply.started":"2021-12-23T18:23:47.356114Z","shell.execute_reply":"2021-12-23T18:23:47.580570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Displaying top 10 colleges having higher number of players","metadata":{}},{"cell_type":"code","source":"top_colleges = college_names[0:10]\nprint(top_colleges)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:47.582164Z","iopub.execute_input":"2021-12-23T18:23:47.582807Z","iopub.status.idle":"2021-12-23T18:23:47.590112Z","shell.execute_reply.started":"2021-12-23T18:23:47.582771Z","shell.execute_reply":"2021-12-23T18:23:47.589186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing top 10 colleges having higher number of players by Donut plot","metadata":{}},{"cell_type":"code","source":"# Creating Donut Plot\nfig = plt.figure(figsize = (12, 13)) \ncircle = plt.Circle( (0,0), 0.5, color = 'white')\nplt.pie(top_colleges[\"Counts\"], labels = top_colleges[\"College Names\"])\np = plt.gcf()\np.gca().add_artist(circle)\nplt.legend(top_colleges[\"Counts\"])\nplt.title(\"Top 10 Colleges Having Higher Number Of Players\", fontsize=25)\n\n# Displaying Donut Plot\nplt.show() ","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:47.591352Z","iopub.execute_input":"2021-12-23T18:23:47.591580Z","iopub.status.idle":"2021-12-23T18:23:47.950707Z","shell.execute_reply.started":"2021-12-23T18:23:47.591552Z","shell.execute_reply":"2021-12-23T18:23:47.949686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Exploring Position column","metadata":{}},{"cell_type":"markdown","source":"**Replacing abbrevated words with keywords.**","metadata":{}},{"cell_type":"code","source":"player[\"Position\"].replace({\"WR\": \"Wide Receiver\", \"CB\": \"Corner Back\", \"DE\": \"Defensive End\", \"OLB\": \"Outside Linebacker\",\n                           \"TE\": \"Tight End\", \"T\": \"Tackle\", \"RB\": \"Running Back\", \"G\": \"Guard\", \"DT\": \"Defensive Tackle\",\n                           \"ILB\": \"Inside Linebacker\", \"FS\": \"Free Safety\", \"SS\": \"Strong Safety\", \"C\": \"Center\", \"K\": \"Kicker\",\n                           \"P\": \"Punter\", \"NT\": \"Nose Tackle\", \"LS\": \"Long Snapper\", \"LB\": \"Linebacker\", \"DB\": \"Defensive Back\",\n                           \"MLB\" : \"Middle Linebacker\", \"FB\": \"Full Back\", \"OT\": \"Offensive Tackle\", \"QB\": \"Quarter Back\",\n                           \"OG\": \"Offensive guard\", \"S\": \"Safety\", \"HB\": \"Half Back\"}, inplace=True)\nprint(player[\"Position\"])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:47.952475Z","iopub.execute_input":"2021-12-23T18:23:47.952723Z","iopub.status.idle":"2021-12-23T18:23:47.970996Z","shell.execute_reply.started":"2021-12-23T18:23:47.952692Z","shell.execute_reply":"2021-12-23T18:23:47.969989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from position column","metadata":{}},{"cell_type":"code","source":"print(\"Unique position values and their counts :\")\npos_val = player.pivot_table(index = ['Position'], aggfunc = 'size') \npos_val = pos_val.reset_index()\npos_val.columns= [\"Positions\", \"Counts\"]\npos_val = pos_val.sort_values(\"Counts\", ascending = False)\nprint(pos_val)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:47.972496Z","iopub.execute_input":"2021-12-23T18:23:47.972735Z","iopub.status.idle":"2021-12-23T18:23:47.989610Z","shell.execute_reply.started":"2021-12-23T18:23:47.972707Z","shell.execute_reply":"2021-12-23T18:23:47.988568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing frequently used to least used positions by Bar plot","metadata":{}},{"cell_type":"code","source":"#  Creating Bar plot\nfig = px.bar(pos_val, x=\"Positions\", y=\"Counts\", title=\"Arrangement Of Positions From Frequently Used To Least Used\", color=pos_val[\"Counts\"])\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:47.991034Z","iopub.execute_input":"2021-12-23T18:23:47.991334Z","iopub.status.idle":"2021-12-23T18:23:48.069996Z","shell.execute_reply.started":"2021-12-23T18:23:47.991302Z","shell.execute_reply":"2021-12-23T18:23:48.069033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Tabular Visualization","metadata":{}},{"cell_type":"markdown","source":"# Player data having highest height in feet","metadata":{}},{"cell_type":"code","source":"height = player[player['height_feet'] == max(player[\"height_feet\"])]\nheight","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.071517Z","iopub.execute_input":"2021-12-23T18:23:48.071851Z","iopub.status.idle":"2021-12-23T18:23:48.095160Z","shell.execute_reply.started":"2021-12-23T18:23:48.071804Z","shell.execute_reply":"2021-12-23T18:23:48.094288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Player data having lowest height in feet","metadata":{}},{"cell_type":"code","source":"low_height = player[player['height_feet'] == min(player[\"height_feet\"])]\nlow_height","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.096400Z","iopub.execute_input":"2021-12-23T18:23:48.096719Z","iopub.status.idle":"2021-12-23T18:23:48.112755Z","shell.execute_reply.started":"2021-12-23T18:23:48.096686Z","shell.execute_reply":"2021-12-23T18:23:48.112092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Player data having highest weight in lbs","metadata":{}},{"cell_type":"code","source":"weight = player[player['weight'] == max(player[\"weight\"])]\nweight","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.113857Z","iopub.execute_input":"2021-12-23T18:23:48.114572Z","iopub.status.idle":"2021-12-23T18:23:48.139205Z","shell.execute_reply.started":"2021-12-23T18:23:48.114536Z","shell.execute_reply":"2021-12-23T18:23:48.138162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Player data having highest weight in lbs","metadata":{}},{"cell_type":"code","source":"low_weight = player[player['weight'] == min(player[\"weight\"])]\nlow_weight","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.140593Z","iopub.execute_input":"2021-12-23T18:23:48.141542Z","iopub.status.idle":"2021-12-23T18:23:48.164230Z","shell.execute_reply.started":"2021-12-23T18:23:48.141503Z","shell.execute_reply":"2021-12-23T18:23:48.163287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Earliest player's data","metadata":{}},{"cell_type":"code","source":"earliest = player[player['birthYear'] == min(player[\"birthYear\"])]\nearliest","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.165656Z","iopub.execute_input":"2021-12-23T18:23:48.166229Z","iopub.status.idle":"2021-12-23T18:23:48.189281Z","shell.execute_reply.started":"2021-12-23T18:23:48.166181Z","shell.execute_reply":"2021-12-23T18:23:48.188364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Newest player's data","metadata":{}},{"cell_type":"code","source":"newest = player[player['birthYear'] == max(player[\"birthYear\"])]\nnewest","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.190831Z","iopub.execute_input":"2021-12-23T18:23:48.191212Z","iopub.status.idle":"2021-12-23T18:23:48.224208Z","shell.execute_reply.started":"2021-12-23T18:23:48.191165Z","shell.execute_reply":"2021-12-23T18:23:48.223245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <p style=\"text-align:center;\"> ✨2. Games Data✨  </p>","metadata":{}},{"cell_type":"markdown","source":"**Game data:** The games.csv contains the teams playing in each game. The key variable is gameId.\n* gameId: Game identifier, unique (numeric)\n* season: Season of game\n* week: Week of game\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 (text)\n* visitorTeamAbbr: Visiting team three-letter code (text)","metadata":{}},{"cell_type":"markdown","source":"# Loading Data","metadata":{}},{"cell_type":"code","source":"games = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/games.csv')\nprint(\"Number of data points:\", len(games))\nprint(\"Number of columns:\", games.shape[1])\ngames","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.226136Z","iopub.execute_input":"2021-12-23T18:23:48.226485Z","iopub.status.idle":"2021-12-23T18:23:48.253259Z","shell.execute_reply.started":"2021-12-23T18:23:48.226426Z","shell.execute_reply":"2021-12-23T18:23:48.252313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Cleaning","metadata":{}},{"cell_type":"markdown","source":"**We want to examine the dataset to know the steps taken to clean the dataset.**","metadata":{}},{"cell_type":"code","source":"# Dataset Summary\ngames.info()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.255144Z","iopub.execute_input":"2021-12-23T18:23:48.255472Z","iopub.status.idle":"2021-12-23T18:23:48.268216Z","shell.execute_reply.started":"2021-12-23T18:23:48.255425Z","shell.execute_reply":"2021-12-23T18:23:48.267219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**From the above output, we can conclude that**\n\n1. The gameDate column should be parsed as DateTime instead of Object.\n\n2. Splitting MM (Month), DD (Date) & YYYY (Year) from MM/DD/YYYY date format.\n\n3. Converting MM (Month) into Month name.\n\n4. Splitting HH (Hour) from HH:MM:SS time format.\n\n5. Replacing abbrevated words with keywords in homeTeamAbbr and visitorTeamAbbr column.","metadata":{}},{"cell_type":"markdown","source":"# Listing out unique values from season column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL seasons and their counts :\")\ng_season = games.pivot_table(index = ['season'], aggfunc = 'size') \ng_season = g_season.reset_index()\ng_season.columns= [\"Seasons\", \"Counts\"]\ng_season = g_season.sort_values(\"Counts\", ascending = False)\nprint(g_season)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.269522Z","iopub.execute_input":"2021-12-23T18:23:48.270092Z","iopub.status.idle":"2021-12-23T18:23:48.287429Z","shell.execute_reply.started":"2021-12-23T18:23:48.270029Z","shell.execute_reply":"2021-12-23T18:23:48.286735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL seasons by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_season, x=\"Seasons\", y=\"Counts\", title=\"NFL Seasons\", color=\"Seasons\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.288474Z","iopub.execute_input":"2021-12-23T18:23:48.289065Z","iopub.status.idle":"2021-12-23T18:23:48.367655Z","shell.execute_reply.started":"2021-12-23T18:23:48.289004Z","shell.execute_reply":"2021-12-23T18:23:48.366744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from week column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL weeks and their counts :\")\ng_week = games.pivot_table(index = ['week'], aggfunc = 'size') \ng_week = g_week.reset_index()\ng_week.columns= [\"Weeks\", \"Counts\"]\ng_week = g_week.sort_values(\"Counts\", ascending = False)\nprint(g_week)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.369125Z","iopub.execute_input":"2021-12-23T18:23:48.369416Z","iopub.status.idle":"2021-12-23T18:23:48.381177Z","shell.execute_reply.started":"2021-12-23T18:23:48.369381Z","shell.execute_reply":"2021-12-23T18:23:48.380294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL weeks by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_week, x=\"Weeks\", y=\"Counts\", title=\"NFL Weeks\", color=\"Weeks\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.382803Z","iopub.execute_input":"2021-12-23T18:23:48.383305Z","iopub.status.idle":"2021-12-23T18:23:48.459247Z","shell.execute_reply.started":"2021-12-23T18:23:48.383270Z","shell.execute_reply":"2021-12-23T18:23:48.458339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from week column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL dates and their counts :\")\ng_date = games.pivot_table(index = ['gameDate'], aggfunc = 'size') \ng_date = g_date.reset_index()\ng_date.columns= [\"Date\", \"Counts\"]\ng_date = g_date.sort_values(\"Counts\", ascending = False)\nprint(g_date)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.460541Z","iopub.execute_input":"2021-12-23T18:23:48.460783Z","iopub.status.idle":"2021-12-23T18:23:48.475735Z","shell.execute_reply.started":"2021-12-23T18:23:48.460752Z","shell.execute_reply":"2021-12-23T18:23:48.475086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL dates by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_date, x=\"Date\", y=\"Counts\", title='Dates On Which NFL Events Occurred', color=\"Counts\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.483670Z","iopub.execute_input":"2021-12-23T18:23:48.484163Z","iopub.status.idle":"2021-12-23T18:23:48.557102Z","shell.execute_reply.started":"2021-12-23T18:23:48.484109Z","shell.execute_reply":"2021-12-23T18:23:48.556182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Feature Engineering - Splitting MM (Month), DD (Date) & YYYY (Year) from MM/DD/YYYY date format","metadata":{}},{"cell_type":"markdown","source":"**Parsing Object as DateTime**","metadata":{}},{"cell_type":"code","source":"print(\"Data type of gameDate column before parsing : \", games[\"gameDate\"].dtypes)\ngames[\"gameDate\"] = pd.to_datetime(games[\"gameDate\"])\nprint(\"Data type of gameDate column after parsing : \", games[\"gameDate\"].dtypes)\nprint(games[\"gameDate\"].head())","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.558631Z","iopub.execute_input":"2021-12-23T18:23:48.559320Z","iopub.status.idle":"2021-12-23T18:23:48.571108Z","shell.execute_reply.started":"2021-12-23T18:23:48.559281Z","shell.execute_reply":"2021-12-23T18:23:48.570302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Splitting YYYY (Year) from MM/DD/YYYY date format**","metadata":{}},{"cell_type":"code","source":"games['gameYear'] = pd.DatetimeIndex(games['gameDate']).year\nprint(games[\"gameYear\"])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.572437Z","iopub.execute_input":"2021-12-23T18:23:48.574233Z","iopub.status.idle":"2021-12-23T18:23:48.583169Z","shell.execute_reply.started":"2021-12-23T18:23:48.574180Z","shell.execute_reply":"2021-12-23T18:23:48.582160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from year column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL years and their counts :\")\ng_year = games.pivot_table(index = ['gameYear'], aggfunc = 'size') \ng_year = g_year.reset_index()\ng_year.columns= [\"Year\", \"Counts\"]\ng_year = g_year.sort_values(\"Counts\", ascending = False)\nprint(g_year)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.584335Z","iopub.execute_input":"2021-12-23T18:23:48.585076Z","iopub.status.idle":"2021-12-23T18:23:48.601866Z","shell.execute_reply.started":"2021-12-23T18:23:48.585016Z","shell.execute_reply":"2021-12-23T18:23:48.600946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL years by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_year, x=\"Year\", y=\"Counts\", title=\"Distinct Count Of NFL Event Years\", color=\"Year\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.603405Z","iopub.execute_input":"2021-12-23T18:23:48.604400Z","iopub.status.idle":"2021-12-23T18:23:48.675850Z","shell.execute_reply.started":"2021-12-23T18:23:48.604364Z","shell.execute_reply":"2021-12-23T18:23:48.674915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Splitting MM (Month) from MM/DD/YYYY date format and converting it into Month name**","metadata":{}},{"cell_type":"code","source":"games[\"gameMonthName\"] = games[\"gameDate\"].dt.month_name()\nprint(games[\"gameMonthName\"])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.677164Z","iopub.execute_input":"2021-12-23T18:23:48.677414Z","iopub.status.idle":"2021-12-23T18:23:48.686311Z","shell.execute_reply.started":"2021-12-23T18:23:48.677382Z","shell.execute_reply":"2021-12-23T18:23:48.685446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from month name column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL months and their counts :\")\ng_month = games.pivot_table(index = ['gameMonthName'], aggfunc = 'size') \ng_month = g_month.reset_index()\ng_month.columns= [\"Month\", \"Counts\"]\ng_month = g_month.sort_values(\"Counts\", ascending = False)\nprint(g_month)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.689551Z","iopub.execute_input":"2021-12-23T18:23:48.690333Z","iopub.status.idle":"2021-12-23T18:23:48.707920Z","shell.execute_reply.started":"2021-12-23T18:23:48.690289Z","shell.execute_reply":"2021-12-23T18:23:48.707022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL months by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_month, x=\"Month\", y=\"Counts\", title=\"Distinct Count Of NFL Event Months\", color=\"Month\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.709283Z","iopub.execute_input":"2021-12-23T18:23:48.710076Z","iopub.status.idle":"2021-12-23T18:23:48.798497Z","shell.execute_reply.started":"2021-12-23T18:23:48.710008Z","shell.execute_reply":"2021-12-23T18:23:48.797551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Splitting DD (Date) from MM/DD/YYYY date format**","metadata":{}},{"cell_type":"code","source":"games['gameDay'] = pd.DatetimeIndex(games['gameDate']).day\nprint(games[\"gameDay\"])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.799922Z","iopub.execute_input":"2021-12-23T18:23:48.800443Z","iopub.status.idle":"2021-12-23T18:23:48.808256Z","shell.execute_reply.started":"2021-12-23T18:23:48.800404Z","shell.execute_reply":"2021-12-23T18:23:48.807424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from day column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL days and their counts :\")\ng_days = games.pivot_table(index = ['gameDay'], aggfunc = 'size') \ng_days = g_days.reset_index()\ng_days.columns= [\"Day\", \"Counts\"]\ng_days = g_days.sort_values(\"Counts\", ascending = False)\nprint(g_days)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.809725Z","iopub.execute_input":"2021-12-23T18:23:48.810324Z","iopub.status.idle":"2021-12-23T18:23:48.829332Z","shell.execute_reply.started":"2021-12-23T18:23:48.810286Z","shell.execute_reply":"2021-12-23T18:23:48.828375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL days by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_days, x=\"Day\", y=\"Counts\", title=\"Distinct Count Of NFL Event Days\", color=\"Counts\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.830718Z","iopub.execute_input":"2021-12-23T18:23:48.830942Z","iopub.status.idle":"2021-12-23T18:23:48.914470Z","shell.execute_reply.started":"2021-12-23T18:23:48.830914Z","shell.execute_reply":"2021-12-23T18:23:48.913538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from gameTimeEastern column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL timings and their counts :\")\ng_time = games.pivot_table(index = ['gameTimeEastern'], aggfunc = 'size') \ng_time = g_time.reset_index()\ng_time.columns= [\"Time\", \"Counts\"]\ng_time = g_time.sort_values(\"Counts\", ascending = False)\nprint(g_time)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.915681Z","iopub.execute_input":"2021-12-23T18:23:48.915933Z","iopub.status.idle":"2021-12-23T18:23:48.928732Z","shell.execute_reply.started":"2021-12-23T18:23:48.915901Z","shell.execute_reply":"2021-12-23T18:23:48.927968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL timings by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_time, x=\"Time\", y=\"Counts\", title=\"Distinct Count Of NFL Event Timings\", color=\"Counts\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:48.929955Z","iopub.execute_input":"2021-12-23T18:23:48.930449Z","iopub.status.idle":"2021-12-23T18:23:49.009206Z","shell.execute_reply.started":"2021-12-23T18:23:48.930399Z","shell.execute_reply":"2021-12-23T18:23:49.008359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Splitting HH (Hour) from HH:MM:SS time format**","metadata":{}},{"cell_type":"code","source":"games[\"hour\"] = pd.to_datetime(games[\"gameTimeEastern\"], format=\"%H:%M:%S\").dt.hour\nprint(games[\"hour\"])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.010489Z","iopub.execute_input":"2021-12-23T18:23:49.010895Z","iopub.status.idle":"2021-12-23T18:23:49.022365Z","shell.execute_reply.started":"2021-12-23T18:23:49.010858Z","shell.execute_reply":"2021-12-23T18:23:49.021133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from hour column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL hours and their counts :\")\ng_hour = games.pivot_table(index = ['hour'], aggfunc = 'size') \ng_hour = g_hour.reset_index()\ng_hour.columns= [\"Hour\", \"Counts\"]\ng_hour = g_hour.sort_values(\"Counts\", ascending = False)\nprint(g_hour)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.023788Z","iopub.execute_input":"2021-12-23T18:23:49.024457Z","iopub.status.idle":"2021-12-23T18:23:49.038579Z","shell.execute_reply.started":"2021-12-23T18:23:49.024379Z","shell.execute_reply":"2021-12-23T18:23:49.037569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL hours by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_hour, x=\"Hour\", y=\"Counts\", title=\"Distinct Count Of NFL Event Hours\", color=\"Counts\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.040425Z","iopub.execute_input":"2021-12-23T18:23:49.041005Z","iopub.status.idle":"2021-12-23T18:23:49.114033Z","shell.execute_reply.started":"2021-12-23T18:23:49.040947Z","shell.execute_reply":"2021-12-23T18:23:49.113088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Exploring homeTeamAbbr column","metadata":{}},{"cell_type":"markdown","source":"**Replacing abbrevated words with keywords.**","metadata":{}},{"cell_type":"code","source":"games[\"homeTeamAbbr\"].replace({\"ARI\": \"Arizona Cardinals\", \"KC\": \"Kansas City Chiefs\", \"TEN\": \"Tennessee Titans\", \"TB\": \"Tampa Bay Buccaneers\",\n                           \"SF\": \"San Francisco 49ers\", \"SEA\": \"Seattle Seahawks\", \"PIT\": \"Pittsburgh Steelers\", \"PHI\": \"Philadelphia Eagles\",\n                            \"NYJ\": \"New York Jets\", \"NYG\": \"New York Giants\", \"NO\": \"New Orleans Saints\", \"NE\": \"New England Patriots\", \n                             \"MIA\": \"Miami Dolphins\", \"ATL\": \"Atlanta Falcons\", \"LA\": \"Los Angeles Rams\", \"JAX\": \"Jacksonville Jaguars\", \n                             \"IND\": \"Indianapolis Colts\", \"BAL\": \"Baltimore Ravens\", \"BUF\": \"Buffalo Bills\", \"CAR\": \"Carolina Panthers\", \n                             \"CIN\": \"Cincinnati Bengals\", \"CLE\": \"Cleveland Browns\", \"DAL\": \"Dallas Cowboys\", \"DET\": \"Detroit Lions\", \n                             \"GB\": \"Green Bay Packers\", \"HOU\": \"Houston Texans\", \"WAS\": \"Washington Football Team\", \"DEN\": \"Denver Broncos\", \n                             \"MIN\": \"Minnesota Vikings\", \"CHI\": \"Chicago Bears\", \"LAC\": \"Los Angeles Chargers\", \"OAK\": \"Oakland Raiders\", \n                             \"LV\": \"Las Vegas Raiders\"}, inplace=True)\nprint(games[\"homeTeamAbbr\"])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.115710Z","iopub.execute_input":"2021-12-23T18:23:49.116530Z","iopub.status.idle":"2021-12-23T18:23:49.134788Z","shell.execute_reply.started":"2021-12-23T18:23:49.116479Z","shell.execute_reply":"2021-12-23T18:23:49.133691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from homeTeamAbbr column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL home teams and their counts :\")\ng_home = games.pivot_table(index = ['homeTeamAbbr'], aggfunc = 'size') \ng_home = g_home.reset_index()\ng_home.columns= [\"Home Team\", \"Counts\"]\ng_home = g_home.sort_values(\"Counts\", ascending = False)\nprint(g_home)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.136214Z","iopub.execute_input":"2021-12-23T18:23:49.136451Z","iopub.status.idle":"2021-12-23T18:23:49.150693Z","shell.execute_reply.started":"2021-12-23T18:23:49.136422Z","shell.execute_reply":"2021-12-23T18:23:49.149697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL Home Teams by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_home, x=\"Home Team\", y=\"Counts\", title=\"Distinct Count Of NFL Home Teams\", color=\"Counts\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.152253Z","iopub.execute_input":"2021-12-23T18:23:49.153081Z","iopub.status.idle":"2021-12-23T18:23:49.224678Z","shell.execute_reply.started":"2021-12-23T18:23:49.153006Z","shell.execute_reply":"2021-12-23T18:23:49.223993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Exploring visitorTeamAbbr column","metadata":{}},{"cell_type":"markdown","source":"**Replacing abbrevated words with keywords.**\n","metadata":{}},{"cell_type":"code","source":"games[\"visitorTeamAbbr\"].replace({\"ARI\": \"Arizona Cardinals\", \"KC\": \"Kansas City Chiefs\", \"TEN\": \"Tennessee Titans\", \"TB\": \"Tampa Bay Buccaneers\",\n                           \"SF\": \"San Francisco 49ers\", \"SEA\": \"Seattle Seahawks\", \"PIT\": \"Pittsburgh Steelers\", \"PHI\": \"Philadelphia Eagles\",\n                            \"NYJ\": \"New York Jets\", \"NYG\": \"New York Giants\", \"NO\": \"New Orleans Saints\", \"NE\": \"New England Patriots\", \n                             \"MIA\": \"Miami Dolphins\", \"ATL\": \"Atlanta Falcons\", \"LA\": \"Los Angeles Rams\", \"JAX\": \"Jacksonville Jaguars\", \n                             \"IND\": \"Indianapolis Colts\", \"BAL\": \"Baltimore Ravens\", \"BUF\": \"Buffalo Bills\", \"CAR\": \"Carolina Panthers\", \n                             \"CIN\": \"Cincinnati Bengals\", \"CLE\": \"Cleveland Browns\", \"DAL\": \"Dallas Cowboys\", \"DET\": \"Detroit Lions\", \n                             \"GB\": \"Green Bay Packers\", \"HOU\": \"Houston Texans\", \"WAS\": \"Washington Football Team\", \"DEN\": \"Denver Broncos\", \n                             \"MIN\": \"Minnesota Vikings\", \"CHI\": \"Chicago Bears\", \"LAC\": \"Los Angeles Chargers\", \"OAK\": \"Oakland Raiders\", \n                             \"LV\": \"Las Vegas Raiders\"}, inplace=True)\nprint(games[\"visitorTeamAbbr\"])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.225969Z","iopub.execute_input":"2021-12-23T18:23:49.226242Z","iopub.status.idle":"2021-12-23T18:23:49.241838Z","shell.execute_reply.started":"2021-12-23T18:23:49.226208Z","shell.execute_reply":"2021-12-23T18:23:49.240604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from visitorTeamAbbr column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL visitor teams and their counts :\")\ng_visit = games.pivot_table(index = ['visitorTeamAbbr'], aggfunc = 'size') \ng_visit = g_visit.reset_index()\ng_visit.columns= [\"Visitor Team\", \"Counts\"]\ng_visit = g_visit.sort_values(\"Counts\", ascending = False)\nprint(g_visit)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.243876Z","iopub.execute_input":"2021-12-23T18:23:49.244532Z","iopub.status.idle":"2021-12-23T18:23:49.260016Z","shell.execute_reply.started":"2021-12-23T18:23:49.244475Z","shell.execute_reply":"2021-12-23T18:23:49.259179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL Visitor Teams by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_visit, x=\"Visitor Team\", y=\"Counts\", title=\"Distinct Count Of NFL Visitor Teams\", color=\"Counts\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.261600Z","iopub.execute_input":"2021-12-23T18:23:49.263245Z","iopub.status.idle":"2021-12-23T18:23:49.332022Z","shell.execute_reply.started":"2021-12-23T18:23:49.263192Z","shell.execute_reply":"2021-12-23T18:23:49.331121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <p style=\"text-align:center;\"> ✨3. Play Data✨  </p>","metadata":{}},{"cell_type":"markdown","source":"**Play data:** The plays.csv file contains play-level information from each game. The key variables are gameId and playId.\n* gameId: Game identifier, unique (numeric)\n* playId: Play identifier, not unique across games (numeric)\n* playDescription: Description of play (text)\n* quarter: Game quarter (numeric)\n* down: Down (numeric)\n* yardsToGo: Distance needed for a first down (numeric)\n* possessionTeam: Team punting, placekicking or kicking off the ball (text)\n* specialTeamsPlayType: Formation of play: Extra Point, Field Goal, Kickoff or Punt (text)\n* specialTeamsResult: 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 (text)\n* kickerId: nflId of placekicker, punter or kickoff specialist on play (numeric)\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 ; (text)\n* kickBlockerId: nflId of blocker of kick on play if there was a blocked field goal or blocked punt (numeric)\n* yardlineSide: 3-letter team code corresponding to line-of-scrimmage (text)\n* yardlineNumber: Yard line at line-of-scrimmage (numeric)\n* gameClock: Time on clock of play (MM:SS)\n* penaltyCodes: NFL categorization of the penalties that occurred on the play. A standard penalty code followed by a d means the penalty was on the defense. Multiple penalties on a play are separated by a ; (text)\n* penaltyJerseyNumber: Jersey number and team code of the player committing each penalty. Multiple penalties on a play are separated by a ; (text)\n* penaltyYards: yards gained by possessionTeam by penalty (numeric)\n* preSnapHomeScore: Home score prior to the play (numeric)\n* preSnapVisitorScore: Visiting team score prior to the play (numeric)\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, ' ': Designed Rush, text)\n* kickLength: Kick length in air of kickoff, field goal or punt (numeric)\n* kickReturnYardage: Yards gained by return team if there was a return on a kickoff or punt (numeric)\n* playResult: Net yards gained by the kicking team, including penalty yardage (numeric)\n* absoluteYardlineNumber: Location of ball downfield in tracking data coordinates (numeric)","metadata":{}},{"cell_type":"markdown","source":"# Loading Data","metadata":{}},{"cell_type":"code","source":"play = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/plays.csv')\nprint(\"Number of data points:\", len(play))\nprint(\"Number of columns:\", play.shape[1])\nplay.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.333336Z","iopub.execute_input":"2021-12-23T18:23:49.334478Z","iopub.status.idle":"2021-12-23T18:23:49.467707Z","shell.execute_reply.started":"2021-12-23T18:23:49.334426Z","shell.execute_reply":"2021-12-23T18:23:49.466779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Cleaning","metadata":{}},{"cell_type":"markdown","source":"**We want to examine the dataset to know the steps taken to clean the dataset.**\n","metadata":{}},{"cell_type":"code","source":"# Dataset Summary\nplay.info()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.469170Z","iopub.execute_input":"2021-12-23T18:23:49.469494Z","iopub.status.idle":"2021-12-23T18:23:49.505339Z","shell.execute_reply.started":"2021-12-23T18:23:49.469451Z","shell.execute_reply":"2021-12-23T18:23:49.504698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**From the above output, we can conclude that**\n\n1. The kickerId, returnerId, kickBlockerId, yardlineSide, penaltyCodes, penaltyJerseyNumbers, penaltyYards, passResult, kickLength and kickReturnYardage column has missing values.\n\n2. Replacing abbrevated words with keywords in possessionTeam and yardlineSide column.\n\n3. Splitting HH (Hour) from HH:MM:SS time format.","metadata":{}},{"cell_type":"markdown","source":"# Eliminate Null Values","metadata":{}},{"cell_type":"code","source":"play_null = play.dropna()\nprint(\"The shape of the dataset after removing null values is : \", play_null.shape)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.506502Z","iopub.execute_input":"2021-12-23T18:23:49.506721Z","iopub.status.idle":"2021-12-23T18:23:49.533294Z","shell.execute_reply.started":"2021-12-23T18:23:49.506692Z","shell.execute_reply":"2021-12-23T18:23:49.532628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**From the above output, we can conclude that if we remove rows containing null values then there would be no data. So we do EDA by omitting the null values.**","metadata":{}},{"cell_type":"markdown","source":"# Listing out unique values from quarter column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL game quarter values and their counts :\")\nplay_qrtr = play.pivot_table(index = ['quarter'], aggfunc = 'size') \nplay_qrtr = play_qrtr.reset_index()\nplay_qrtr.columns= [\"Quarter\", \"Counts\"]\nplay_qrtr = play_qrtr.sort_values(\"Counts\", ascending = False)\nprint(play_qrtr)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.534266Z","iopub.execute_input":"2021-12-23T18:23:49.535091Z","iopub.status.idle":"2021-12-23T18:23:49.546268Z","shell.execute_reply.started":"2021-12-23T18:23:49.535055Z","shell.execute_reply":"2021-12-23T18:23:49.545462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL game quarters by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(play_qrtr, x=\"Quarter\", y=\"Counts\", title=\"Distinct Count Of NFL Game Quarters\", color=\"Quarter\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.547319Z","iopub.execute_input":"2021-12-23T18:23:49.548092Z","iopub.status.idle":"2021-12-23T18:23:49.627642Z","shell.execute_reply.started":"2021-12-23T18:23:49.548050Z","shell.execute_reply":"2021-12-23T18:23:49.626770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from down column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL game downs and their counts :\")\ng_down = play.pivot_table(index = ['down'], aggfunc = 'size') \ng_down = g_down.reset_index()\ng_down.columns= [\"Down\", \"Counts\"]\ng_down = g_down.sort_values(\"Counts\", ascending = False)\nprint(g_down)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.628787Z","iopub.execute_input":"2021-12-23T18:23:49.629364Z","iopub.status.idle":"2021-12-23T18:23:49.640019Z","shell.execute_reply.started":"2021-12-23T18:23:49.629332Z","shell.execute_reply":"2021-12-23T18:23:49.639202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL game downs by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_down, x=\"Down\", y=\"Counts\", title=\"Distinct Count Of NFL Game Downs\", color=\"Down\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.641295Z","iopub.execute_input":"2021-12-23T18:23:49.641525Z","iopub.status.idle":"2021-12-23T18:23:49.711304Z","shell.execute_reply.started":"2021-12-23T18:23:49.641496Z","shell.execute_reply":"2021-12-23T18:23:49.710343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from yardsToGo column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL yards to go and their counts :\")\ng_yards = play.pivot_table(index = ['yardsToGo'], aggfunc = 'size') \ng_yards = g_yards.reset_index()\ng_yards.columns= [\"Yards To Go\", \"Counts\"]\ng_yards = g_yards.sort_values(\"Counts\", ascending = False)\nprint(g_yards)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.712846Z","iopub.execute_input":"2021-12-23T18:23:49.713280Z","iopub.status.idle":"2021-12-23T18:23:49.727142Z","shell.execute_reply.started":"2021-12-23T18:23:49.713231Z","shell.execute_reply":"2021-12-23T18:23:49.726386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL yards to go by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_yards, x=\"Yards To Go\", y=\"Counts\", title=\"Distinct Count Of Yards To Go In NFL Game\", color=\"Yards To Go\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.728031Z","iopub.execute_input":"2021-12-23T18:23:49.728842Z","iopub.status.idle":"2021-12-23T18:23:49.797488Z","shell.execute_reply.started":"2021-12-23T18:23:49.728803Z","shell.execute_reply":"2021-12-23T18:23:49.796914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Exploring possessionTeam column","metadata":{}},{"cell_type":"markdown","source":"**Replacing abbrevated words with keywords.**","metadata":{}},{"cell_type":"code","source":"play[\"possessionTeam\"].replace({\"ARI\": \"Arizona Cardinals\", \"KC\": \"Kansas City Chiefs\", \"TEN\": \"Tennessee Titans\", \"TB\": \"Tampa Bay Buccaneers\",\n                           \"SF\": \"San Francisco 49ers\", \"SEA\": \"Seattle Seahawks\", \"PIT\": \"Pittsburgh Steelers\", \"PHI\": \"Philadelphia Eagles\",\n                            \"NYJ\": \"New York Jets\", \"NYG\": \"New York Giants\", \"NO\": \"New Orleans Saints\", \"NE\": \"New England Patriots\", \n                             \"MIA\": \"Miami Dolphins\", \"ATL\": \"Atlanta Falcons\", \"LA\": \"Los Angeles Rams\", \"JAX\": \"Jacksonville Jaguars\", \n                             \"IND\": \"Indianapolis Colts\", \"BAL\": \"Baltimore Ravens\", \"BUF\": \"Buffalo Bills\", \"CAR\": \"Carolina Panthers\", \n                             \"CIN\": \"Cincinnati Bengals\", \"CLE\": \"Cleveland Browns\", \"DAL\": \"Dallas Cowboys\", \"DET\": \"Detroit Lions\", \n                             \"GB\": \"Green Bay Packers\", \"HOU\": \"Houston Texans\", \"WAS\": \"Washington Football Team\", \"DEN\": \"Denver Broncos\", \n                             \"MIN\": \"Minnesota Vikings\", \"CHI\": \"Chicago Bears\", \"LAC\": \"Los Angeles Chargers\", \"OAK\": \"Oakland Raiders\", \n                             \"LV\": \"Las Vegas Raiders\"}, inplace=True)\nprint(play[\"possessionTeam\"])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.798445Z","iopub.execute_input":"2021-12-23T18:23:49.799069Z","iopub.status.idle":"2021-12-23T18:23:49.852246Z","shell.execute_reply.started":"2021-12-23T18:23:49.799022Z","shell.execute_reply":"2021-12-23T18:23:49.850465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from possessionTeam column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL possession teams and their counts :\")\np_team = play.pivot_table(index = ['possessionTeam'], aggfunc = 'size') \np_team = p_team.reset_index()\np_team.columns= [\"Possession Team\", \"Counts\"]\np_team = p_team.sort_values(\"Counts\", ascending = False)\nprint(p_team)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.853751Z","iopub.execute_input":"2021-12-23T18:23:49.854110Z","iopub.status.idle":"2021-12-23T18:23:49.868964Z","shell.execute_reply.started":"2021-12-23T18:23:49.854063Z","shell.execute_reply":"2021-12-23T18:23:49.868352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL Possession Teams by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(p_team, x=\"Possession Team\", y=\"Counts\", title=\"Distinct Count Of NFL Possession Teams\", color=\"Counts\")\n\n# Displaying Bar plot\nfig.show()\n","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.870034Z","iopub.execute_input":"2021-12-23T18:23:49.870692Z","iopub.status.idle":"2021-12-23T18:23:49.941053Z","shell.execute_reply.started":"2021-12-23T18:23:49.870655Z","shell.execute_reply":"2021-12-23T18:23:49.940209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from specialTeamsPlayType column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL special teams play type and their counts :\")\ngp_type = play.pivot_table(index = ['specialTeamsPlayType'], aggfunc = 'size') \ngp_type = gp_type.reset_index()\ngp_type.columns= [\"Special Teams Play Type\", \"Counts\"]\ngp_type = gp_type.sort_values(\"Counts\", ascending = False)\nprint(gp_type)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.942061Z","iopub.execute_input":"2021-12-23T18:23:49.942272Z","iopub.status.idle":"2021-12-23T18:23:49.957564Z","shell.execute_reply.started":"2021-12-23T18:23:49.942246Z","shell.execute_reply":"2021-12-23T18:23:49.956514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL Special Teams play type by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(gp_type, x=\"Special Teams Play Type\", y=\"Counts\", title=\"Distinct Count Of NFL Special Teams Play Type\", color=\"Counts\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:49.960842Z","iopub.execute_input":"2021-12-23T18:23:49.961127Z","iopub.status.idle":"2021-12-23T18:23:50.032212Z","shell.execute_reply.started":"2021-12-23T18:23:49.961093Z","shell.execute_reply":"2021-12-23T18:23:50.031018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from specialTeamsResult column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL special teams result and their counts :\")\ngp_res = play.pivot_table(index = ['specialTeamsResult'], aggfunc = 'size') \ngp_res = gp_res.reset_index()\ngp_res.columns= [\"Special Teams Result\", \"Counts\"]\ngp_res = gp_res.sort_values(\"Counts\", ascending = False)\nprint(gp_res)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.033905Z","iopub.execute_input":"2021-12-23T18:23:50.034311Z","iopub.status.idle":"2021-12-23T18:23:50.051203Z","shell.execute_reply.started":"2021-12-23T18:23:50.034265Z","shell.execute_reply":"2021-12-23T18:23:50.050114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL Special Teams result by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(gp_res, x=\"Special Teams Result\", y=\"Counts\", title=\"Distinct Count Of NFL Special Teams Result\", color=\"Counts\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.052851Z","iopub.execute_input":"2021-12-23T18:23:50.053540Z","iopub.status.idle":"2021-12-23T18:23:50.127284Z","shell.execute_reply.started":"2021-12-23T18:23:50.053479Z","shell.execute_reply":"2021-12-23T18:23:50.126029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Exploring yardline side column","metadata":{}},{"cell_type":"markdown","source":"**Replacing abbrevated words with keywords.**","metadata":{}},{"cell_type":"code","source":"play[\"yardlineSide\"].replace({\"ARI\": \"Arizona Cardinals\", \"KC\": \"Kansas City Chiefs\", \"TEN\": \"Tennessee Titans\", \"TB\": \"Tampa Bay Buccaneers\",\n                           \"SF\": \"San Francisco 49ers\", \"SEA\": \"Seattle Seahawks\", \"PIT\": \"Pittsburgh Steelers\", \"PHI\": \"Philadelphia Eagles\",\n                            \"NYJ\": \"New York Jets\", \"NYG\": \"New York Giants\", \"NO\": \"New Orleans Saints\", \"NE\": \"New England Patriots\", \n                             \"MIA\": \"Miami Dolphins\", \"ATL\": \"Atlanta Falcons\", \"LA\": \"Los Angeles Rams\", \"JAX\": \"Jacksonville Jaguars\", \n                             \"IND\": \"Indianapolis Colts\", \"BAL\": \"Baltimore Ravens\", \"BUF\": \"Buffalo Bills\", \"CAR\": \"Carolina Panthers\", \n                             \"CIN\": \"Cincinnati Bengals\", \"CLE\": \"Cleveland Browns\", \"DAL\": \"Dallas Cowboys\", \"DET\": \"Detroit Lions\", \n                             \"GB\": \"Green Bay Packers\", \"HOU\": \"Houston Texans\", \"WAS\": \"Washington Football Team\", \"DEN\": \"Denver Broncos\", \n                             \"MIN\": \"Minnesota Vikings\", \"CHI\": \"Chicago Bears\", \"LAC\": \"Los Angeles Chargers\", \"OAK\": \"Oakland Raiders\", \n                             \"LV\": \"Las Vegas Raiders\"}, inplace=True)\nprint(play[\"yardlineSide\"])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.129351Z","iopub.execute_input":"2021-12-23T18:23:50.129712Z","iopub.status.idle":"2021-12-23T18:23:50.184450Z","shell.execute_reply.started":"2021-12-23T18:23:50.129663Z","shell.execute_reply":"2021-12-23T18:23:50.183510Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from NFL yardline side column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL yardline sides and their counts :\")\ng_yard = play.pivot_table(index = ['yardlineSide'], aggfunc = 'size') \ng_yard = g_yard.reset_index()\ng_yard.columns= [\"Yard Line Side\", \"Counts\"]\ng_yard = g_yard.sort_values(\"Counts\", ascending = False)\nprint(g_yard)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.185932Z","iopub.execute_input":"2021-12-23T18:23:50.186317Z","iopub.status.idle":"2021-12-23T18:23:50.202030Z","shell.execute_reply.started":"2021-12-23T18:23:50.186270Z","shell.execute_reply":"2021-12-23T18:23:50.201355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL yardline sides by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_yard, x=\"Yard Line Side\", y=\"Counts\", title=\"Distinct Count Of NFL Yardline Sides\", color=\"Counts\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.203623Z","iopub.execute_input":"2021-12-23T18:23:50.204154Z","iopub.status.idle":"2021-12-23T18:23:50.279105Z","shell.execute_reply.started":"2021-12-23T18:23:50.204071Z","shell.execute_reply":"2021-12-23T18:23:50.278133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from yardline number column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL yardline numbers and their counts :\")\ng_yard = play.pivot_table(index = ['yardlineNumber'], aggfunc = 'size') \ng_yard = g_yard.reset_index()\ng_yard.columns= [\"Yard Line Number\", \"Counts\"]\ng_yard = g_yard.sort_values(\"Counts\", ascending = False)\nprint(g_yard)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.280537Z","iopub.execute_input":"2021-12-23T18:23:50.280787Z","iopub.status.idle":"2021-12-23T18:23:50.292941Z","shell.execute_reply.started":"2021-12-23T18:23:50.280755Z","shell.execute_reply":"2021-12-23T18:23:50.292069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL yardline numbers by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_yard, x=\"Yard Line Number\", y=\"Counts\", title=\"Distinct Count Of NFL Yard Line Numbers\", color=\"Yard Line Number\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.294518Z","iopub.execute_input":"2021-12-23T18:23:50.294934Z","iopub.status.idle":"2021-12-23T18:23:50.367244Z","shell.execute_reply.started":"2021-12-23T18:23:50.294884Z","shell.execute_reply":"2021-12-23T18:23:50.366296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Feature Engineering - gameClockhour column","metadata":{}},{"cell_type":"markdown","source":"**Splitting HH (Hour) from HH:MM:SS time format**","metadata":{}},{"cell_type":"code","source":"play[\"gameClockhour\"] = pd.to_datetime(play[\"gameClock\"], format=\"%H:%M:%S\").dt.hour\nprint(play[\"gameClockhour\"])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.368821Z","iopub.execute_input":"2021-12-23T18:23:50.369350Z","iopub.status.idle":"2021-12-23T18:23:50.391757Z","shell.execute_reply.started":"2021-12-23T18:23:50.369303Z","shell.execute_reply":"2021-12-23T18:23:50.391099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from game clock hour column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL game hours and their counts :\")\ng_hour = play.pivot_table(index = ['gameClockhour'], aggfunc = 'size') \ng_hour = g_hour.reset_index()\ng_hour.columns= [\"Game Hour\", \"Counts\"]\ng_hour = g_hour.sort_values(\"Counts\", ascending = False)\nprint(g_hour)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.392760Z","iopub.execute_input":"2021-12-23T18:23:50.393399Z","iopub.status.idle":"2021-12-23T18:23:50.404459Z","shell.execute_reply.started":"2021-12-23T18:23:50.393365Z","shell.execute_reply":"2021-12-23T18:23:50.403517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL game hours by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_hour, x=\"Game Hour\", y=\"Counts\", title=\"Distinct Count Of NFL Game Hours\", color=\"Counts\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.405937Z","iopub.execute_input":"2021-12-23T18:23:50.406665Z","iopub.status.idle":"2021-12-23T18:23:50.474089Z","shell.execute_reply.started":"2021-12-23T18:23:50.406627Z","shell.execute_reply":"2021-12-23T18:23:50.473489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from penalty codes column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL penalty codes and their counts :\")\ng_code = play.pivot_table(index = ['penaltyCodes'], aggfunc = 'size') \ng_code = g_code.reset_index()\ng_code.columns= [\"Penalty Codes\", \"Counts\"]\ng_code = g_code.sort_values(\"Counts\", ascending = False)\nprint(g_code)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.475201Z","iopub.execute_input":"2021-12-23T18:23:50.475540Z","iopub.status.idle":"2021-12-23T18:23:50.490758Z","shell.execute_reply.started":"2021-12-23T18:23:50.475510Z","shell.execute_reply":"2021-12-23T18:23:50.490156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL penalty codes by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_code, x=\"Penalty Codes\", y=\"Counts\", title=\"Distinct Count Of NFL Penalty Codes\", color=\"Counts\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.492060Z","iopub.execute_input":"2021-12-23T18:23:50.492506Z","iopub.status.idle":"2021-12-23T18:23:50.561187Z","shell.execute_reply.started":"2021-12-23T18:23:50.492472Z","shell.execute_reply":"2021-12-23T18:23:50.560300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from penalty yards column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL penalty yards and their counts :\")\ngp_yard = play.pivot_table(index = ['penaltyYards'], aggfunc = 'size') \ngp_yard = gp_yard.reset_index()\ngp_yard.columns= [\"Penalty Yards\", \"Counts\"]\ngp_yard = gp_yard.sort_values(\"Counts\", ascending = False)\nprint(gp_yard)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.562374Z","iopub.execute_input":"2021-12-23T18:23:50.562606Z","iopub.status.idle":"2021-12-23T18:23:50.575495Z","shell.execute_reply.started":"2021-12-23T18:23:50.562577Z","shell.execute_reply":"2021-12-23T18:23:50.574673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL penalty yards by Histogram plot","metadata":{}},{"cell_type":"code","source":"# Creating Histogram plot\nfig = px.histogram(play, x=\"penaltyYards\", nbins=15 , title=\"Distinct Count Of NFL Visitor Teams\", color_discrete_sequence=[\"royalblue\"])\n\n# Displaying Histogram plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.576704Z","iopub.execute_input":"2021-12-23T18:23:50.577482Z","iopub.status.idle":"2021-12-23T18:23:50.733883Z","shell.execute_reply.started":"2021-12-23T18:23:50.577424Z","shell.execute_reply":"2021-12-23T18:23:50.732954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from pre-snap home score column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL pre-snap home scores and their counts :\")\ng_home = play.pivot_table(index = ['preSnapHomeScore'], aggfunc = 'size') \ng_home = g_home.reset_index()\ng_home.columns= [\"Pre-Snap Home Score\", \"Counts\"]\ng_home = g_home.sort_values(\"Counts\", ascending = False)\nprint(g_home)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.735315Z","iopub.execute_input":"2021-12-23T18:23:50.736216Z","iopub.status.idle":"2021-12-23T18:23:50.751457Z","shell.execute_reply.started":"2021-12-23T18:23:50.736176Z","shell.execute_reply":"2021-12-23T18:23:50.750411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL pre-snap home scores by Histogram plot","metadata":{}},{"cell_type":"code","source":"# Creating Histogram plot\nfig = px.histogram(play, x=\"preSnapHomeScore\", nbins=25, title=\"Distinct Count Of NFL Pre-Snap Home Scores\", color_discrete_sequence=[\"red\"])\n\n# Displaying Histogram plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.753003Z","iopub.execute_input":"2021-12-23T18:23:50.753598Z","iopub.status.idle":"2021-12-23T18:23:50.896362Z","shell.execute_reply.started":"2021-12-23T18:23:50.753550Z","shell.execute_reply":"2021-12-23T18:23:50.895445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from pre-snap visitor score column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL pre-snap visitor scores and their counts :\")\ng_visitor = play.pivot_table(index = ['preSnapVisitorScore'], aggfunc = 'size') \ng_visitor = g_visitor.reset_index()\ng_visitor.columns= [\"Pre-Snap Visitor Score\", \"Counts\"]\ng_visitor = g_visitor.sort_values(\"Counts\", ascending = False)\nprint(g_visitor)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.897745Z","iopub.execute_input":"2021-12-23T18:23:50.898253Z","iopub.status.idle":"2021-12-23T18:23:50.916063Z","shell.execute_reply.started":"2021-12-23T18:23:50.898206Z","shell.execute_reply":"2021-12-23T18:23:50.915138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL pre-snap visitor scores by Histogram plot","metadata":{}},{"cell_type":"code","source":"# Creating Histogram plot\nfig = px.histogram(play, x=\"preSnapVisitorScore\", nbins=25, title=\"Distinct Count Of NFL Pre-Snap Visitor Scores\", color_discrete_sequence=[\"blueviolet\"])\n\n# Displaying Histogram plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:50.917432Z","iopub.execute_input":"2021-12-23T18:23:50.918132Z","iopub.status.idle":"2021-12-23T18:23:51.236272Z","shell.execute_reply.started":"2021-12-23T18:23:50.918086Z","shell.execute_reply":"2021-12-23T18:23:51.235244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from pass result column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL pass results and their counts :\")\ng_res = play.pivot_table(index = ['passResult'], aggfunc = 'size') \ng_res = g_res.reset_index()\ng_res.columns= [\"Pass Results\", \"Counts\"]\ng_res = g_res.sort_values(\"Counts\", ascending = False)\nprint(g_res)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:51.237712Z","iopub.execute_input":"2021-12-23T18:23:51.238067Z","iopub.status.idle":"2021-12-23T18:23:51.253570Z","shell.execute_reply.started":"2021-12-23T18:23:51.237977Z","shell.execute_reply":"2021-12-23T18:23:51.252827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL pass results by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_res, x=\"Pass Results\", y=\"Counts\", title=\"Distinct Count Of NFL Pass Results\", color=\"Counts\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:51.254921Z","iopub.execute_input":"2021-12-23T18:23:51.255488Z","iopub.status.idle":"2021-12-23T18:23:51.324124Z","shell.execute_reply.started":"2021-12-23T18:23:51.255450Z","shell.execute_reply":"2021-12-23T18:23:51.323256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from kick-length column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL kick lengths and their counts :\")\ng_kick = play.pivot_table(index = ['kickLength'], aggfunc = 'size') \ng_kick = g_kick.reset_index()\ng_kick.columns= [\"Kick Length\", \"Counts\"]\ng_kick = g_kick.sort_values(\"Counts\", ascending = False)\nprint(g_kick)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:51.325487Z","iopub.execute_input":"2021-12-23T18:23:51.325842Z","iopub.status.idle":"2021-12-23T18:23:51.341939Z","shell.execute_reply.started":"2021-12-23T18:23:51.325794Z","shell.execute_reply":"2021-12-23T18:23:51.341122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL kick lengths by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_kick, x=\"Kick Length\", y=\"Counts\", title=\"Distinct Count Of NFL Kick lengths\", color=\"Kick Length\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:51.344925Z","iopub.execute_input":"2021-12-23T18:23:51.345198Z","iopub.status.idle":"2021-12-23T18:23:51.416646Z","shell.execute_reply.started":"2021-12-23T18:23:51.345168Z","shell.execute_reply":"2021-12-23T18:23:51.415966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from kick return yardage column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL kick return yardages and their counts :\")\ng_yard = play.pivot_table(index = ['kickReturnYardage'], aggfunc = 'size') \ng_yard = g_yard.reset_index()\ng_yard.columns= [\"Kick Return Yardage\", \"Counts\"]\ng_yard = g_yard.sort_values(\"Counts\", ascending = False)\nprint(g_yard)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:51.417648Z","iopub.execute_input":"2021-12-23T18:23:51.417992Z","iopub.status.idle":"2021-12-23T18:23:51.433904Z","shell.execute_reply.started":"2021-12-23T18:23:51.417961Z","shell.execute_reply":"2021-12-23T18:23:51.432752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL kick return yardages by Histogram plot","metadata":{}},{"cell_type":"code","source":"# Creating Histogram plot\nfig = px.histogram(play, x=\"kickReturnYardage\", nbins=25 , title=\"Distinct Count Of NFL Kick Return Yardages\",  color_discrete_sequence=[\"mediumvioletred\"])\n\n# Displaying Histogram plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:51.435679Z","iopub.execute_input":"2021-12-23T18:23:51.436227Z","iopub.status.idle":"2021-12-23T18:23:51.580599Z","shell.execute_reply.started":"2021-12-23T18:23:51.436178Z","shell.execute_reply":"2021-12-23T18:23:51.579708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from play results column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL play results and their counts :\")\ngp_res = play.pivot_table(index = ['playResult'], aggfunc = 'size') \ngp_res = gp_res.reset_index()\ngp_res.columns= [\"Play Result\", \"Counts\"]\ngp_res = gp_res.sort_values(\"Counts\", ascending = False)\nprint(gp_res)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:51.581765Z","iopub.execute_input":"2021-12-23T18:23:51.581994Z","iopub.status.idle":"2021-12-23T18:23:51.595274Z","shell.execute_reply.started":"2021-12-23T18:23:51.581966Z","shell.execute_reply":"2021-12-23T18:23:51.594357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL play results by Histogram plot","metadata":{}},{"cell_type":"code","source":"# Creating Histogram plot\nfig = px.histogram(play, x=\"playResult\", nbins=10, title=\"Distinct Count Of NFL Play Results\", color_discrete_sequence=[\"blue\"])\n\n# Displaying Histogram plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:51.596502Z","iopub.execute_input":"2021-12-23T18:23:51.596747Z","iopub.status.idle":"2021-12-23T18:23:51.738114Z","shell.execute_reply.started":"2021-12-23T18:23:51.596715Z","shell.execute_reply":"2021-12-23T18:23:51.737144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from absolute yardline number column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL absolute yardline numbers and their counts :\")\ng_abyl = play.pivot_table(index = ['absoluteYardlineNumber'], aggfunc = 'size') \ng_abyl = g_abyl.reset_index()\ng_abyl.columns= [\"Absolute YardLine Number\", \"Counts\"]\ng_abyl = g_abyl.sort_values(\"Counts\", ascending = False)\nprint(g_abyl)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:51.739434Z","iopub.execute_input":"2021-12-23T18:23:51.739690Z","iopub.status.idle":"2021-12-23T18:23:51.753103Z","shell.execute_reply.started":"2021-12-23T18:23:51.739657Z","shell.execute_reply":"2021-12-23T18:23:51.752123Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL absolute yardline numbers by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(g_abyl, x=\"Absolute YardLine Number\", y=\"Counts\", title=\"Distinct Count Of NFL Absolute Yard Line Number\", color=\"Absolute YardLine Number\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:51.754503Z","iopub.execute_input":"2021-12-23T18:23:51.754929Z","iopub.status.idle":"2021-12-23T18:23:51.825879Z","shell.execute_reply.started":"2021-12-23T18:23:51.754898Z","shell.execute_reply":"2021-12-23T18:23:51.825014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <p style=\"text-align:center;\"> ✨4. Tracking data - 2018✨  </p>","metadata":{}},{"cell_type":"markdown","source":"**Tracking data - 2018:** Files tracking2018.csv contain player tracking data from season 2018. The key variables are gameId, playId, and nflId.\n\n* time: Time stamp of play (time, yyyy-mm-dd, hh:mm:ss)\n* x: Player position along the long axis of the field, 0 - 120 yards. See Figure 1 below. (numeric)\n* y: Player position along the short axis of the field, 0 - 53.3 yards. See Figure 1 below. (numeric)\n* s: Speed in yards/second (numeric)\n* a: Acceleration in yards/second^2 (numeric)\n* dis: Distance traveled from prior time point, in yards (numeric)\n* o: Player orientation (deg), 0 - 360 degrees (numeric)\n* dir: Angle of player motion (deg), 0 - 360 degrees (numeric)\n* event: Tagged play details, including moment of ball snap, pass release, pass catch, tackle, etc (text)\n* nflId: Player identification number, unique across players (numeric)\n* displayName: Player name (text)\n* jerseyNumber: Jersey number of player (numeric)\n* position: Player position group (text)\n* team: Team (away or home) of corresponding player (text)\n* frameId: Frame identifier for each play, starting at 1 (numeric)\n* gameId: Game identifier, unique (numeric)\n* playId: Play identifier, not unique across games (numeric)\n* playDirection: Direction that the offense is moving (left or right)","metadata":{}},{"cell_type":"markdown","source":"# Loading Data","metadata":{}},{"cell_type":"code","source":"tr18 = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/tracking2018.csv')\nprint(\"Number of data points:\", len(tr18))\nprint(\"Number of columns:\", tr18.shape[1])\ntr18.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:23:51.827394Z","iopub.execute_input":"2021-12-23T18:23:51.827790Z","iopub.status.idle":"2021-12-23T18:24:26.714717Z","shell.execute_reply.started":"2021-12-23T18:23:51.827738Z","shell.execute_reply":"2021-12-23T18:24:26.714097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Dataset Summary","metadata":{}},{"cell_type":"code","source":"tr18.info()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:24:26.715814Z","iopub.execute_input":"2021-12-23T18:24:26.716488Z","iopub.status.idle":"2021-12-23T18:24:26.728493Z","shell.execute_reply.started":"2021-12-23T18:24:26.716449Z","shell.execute_reply":"2021-12-23T18:24:26.727817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**From the above output, we can conclude that split date from datetime.**","metadata":{}},{"cell_type":"markdown","source":"# Feature Engineering - Splitting date from datetime","metadata":{}},{"cell_type":"code","source":"tr18['date'] = pd.DatetimeIndex(tr18['time']).date\nprint(tr18[\"date\"])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:24:26.729652Z","iopub.execute_input":"2021-12-23T18:24:26.730422Z","iopub.status.idle":"2021-12-23T18:24:37.534845Z","shell.execute_reply.started":"2021-12-23T18:24:26.730383Z","shell.execute_reply":"2021-12-23T18:24:37.533953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Listing out unique values from date column","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL dates and their counts :\")\ntr_date = tr18.pivot_table(index = ['date'], aggfunc = 'size') \ntr_date = tr_date.reset_index()\ntr_date.columns= [\"Date\", \"Counts\"]\ntr_date = tr_date.sort_values(\"Counts\", ascending = False)\nprint(tr_date)","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:24:37.536473Z","iopub.execute_input":"2021-12-23T18:24:37.536779Z","iopub.status.idle":"2021-12-23T18:24:40.339947Z","shell.execute_reply.started":"2021-12-23T18:24:37.536744Z","shell.execute_reply":"2021-12-23T18:24:40.338970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing NFL dates by Bar plot","metadata":{}},{"cell_type":"code","source":"# Creating Bar plot\nfig = px.bar(tr_date, x=\"Date\", y=\"Counts\", title=\"Distinct Count Of NFL Dates\", color=\"Counts\")\n\n# Displaying Bar plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:24:40.341642Z","iopub.execute_input":"2021-12-23T18:24:40.341945Z","iopub.status.idle":"2021-12-23T18:24:40.431572Z","shell.execute_reply.started":"2021-12-23T18:24:40.341903Z","shell.execute_reply":"2021-12-23T18:24:40.430591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Creating new dataset using playId, position and gameId","metadata":{}},{"cell_type":"markdown","source":"**playId == 36 and gameId == 2018123000**","metadata":{}},{"cell_type":"code","source":"data = tr18.query('playId == 36 and gameId == 2018123000')\nprint(data[[\"x\", \"y\", \"team\"]])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:24:40.433927Z","iopub.execute_input":"2021-12-23T18:24:40.434196Z","iopub.status.idle":"2021-12-23T18:24:44.040876Z","shell.execute_reply.started":"2021-12-23T18:24:40.434164Z","shell.execute_reply":"2021-12-23T18:24:44.039581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing data regarding playId = 36 and gameId = 2018123000","metadata":{}},{"cell_type":"code","source":"fig = px.scatter(data, x=\"x\", y=\"y\", color=\"team\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:24:44.042469Z","iopub.execute_input":"2021-12-23T18:24:44.042800Z","iopub.status.idle":"2021-12-23T18:24:44.136277Z","shell.execute_reply.started":"2021-12-23T18:24:44.042761Z","shell.execute_reply":"2021-12-23T18:24:44.135061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**playId == 36 and gameId == 2018102107**","metadata":{}},{"cell_type":"code","source":"data = tr18.query('playId == 36 and gameId == 2018102107')\nprint(data[[\"x\", \"y\", \"team\"]])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:24:44.137625Z","iopub.execute_input":"2021-12-23T18:24:44.137888Z","iopub.status.idle":"2021-12-23T18:24:44.239336Z","shell.execute_reply.started":"2021-12-23T18:24:44.137853Z","shell.execute_reply":"2021-12-23T18:24:44.238237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing data regarding playId = 36 and gameId = 2018102107","metadata":{}},{"cell_type":"code","source":"fig = px.scatter(data, x=\"x\", y=\"y\", color=\"team\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:24:44.240785Z","iopub.execute_input":"2021-12-23T18:24:44.241105Z","iopub.status.idle":"2021-12-23T18:24:44.324628Z","shell.execute_reply.started":"2021-12-23T18:24:44.241068Z","shell.execute_reply":"2021-12-23T18:24:44.323707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**position == \"CB\" and gameId == 2018111900**","metadata":{}},{"cell_type":"code","source":"data = tr18.query('position == \"CB\" and gameId == 2018111900')\nprint(data[[\"x\", \"y\", \"team\"]])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:24:44.325869Z","iopub.execute_input":"2021-12-23T18:24:44.326131Z","iopub.status.idle":"2021-12-23T18:24:44.861304Z","shell.execute_reply.started":"2021-12-23T18:24:44.326100Z","shell.execute_reply":"2021-12-23T18:24:44.860076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing data regarding position = CB and gameId = 2018111900","metadata":{}},{"cell_type":"code","source":"fig = px.scatter(data, x=\"x\", y=\"y\", color=\"team\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:24:44.862540Z","iopub.execute_input":"2021-12-23T18:24:44.862864Z","iopub.status.idle":"2021-12-23T18:24:44.958197Z","shell.execute_reply.started":"2021-12-23T18:24:44.862827Z","shell.execute_reply":"2021-12-23T18:24:44.957122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**position == \"RB\" and gameId == 2018093009**","metadata":{}},{"cell_type":"code","source":"data = tr18.query('position == \"RB\" and gameId == 2018093009')\nprint(data[[\"x\", \"y\", \"team\"]])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:24:44.959849Z","iopub.execute_input":"2021-12-23T18:24:44.960266Z","iopub.status.idle":"2021-12-23T18:24:45.423824Z","shell.execute_reply.started":"2021-12-23T18:24:44.960221Z","shell.execute_reply":"2021-12-23T18:24:45.423059Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing data regarding position = RB and gameId = 2018093009","metadata":{}},{"cell_type":"code","source":"fig = px.scatter(data, x=\"x\", y=\"y\", color=\"team\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:24:45.426131Z","iopub.execute_input":"2021-12-23T18:24:45.426732Z","iopub.status.idle":"2021-12-23T18:24:45.503534Z","shell.execute_reply.started":"2021-12-23T18:24:45.426680Z","shell.execute_reply":"2021-12-23T18:24:45.502915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**position == \"LB\" and gameId == 2018111900**","metadata":{}},{"cell_type":"code","source":"data = tr18.query('position == \"LB\" and gameId == 2018111900')\nprint(data[[\"x\", \"y\", \"team\"]])","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:24:45.504611Z","iopub.execute_input":"2021-12-23T18:24:45.504964Z","iopub.status.idle":"2021-12-23T18:24:45.971694Z","shell.execute_reply.started":"2021-12-23T18:24:45.504933Z","shell.execute_reply":"2021-12-23T18:24:45.970807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing data regarding position = LB and gameId = 2018111900","metadata":{}},{"cell_type":"code","source":"fig = px.scatter(data, x=\"x\", y=\"y\", color=\"team\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:24:45.973320Z","iopub.execute_input":"2021-12-23T18:24:45.973853Z","iopub.status.idle":"2021-12-23T18:24:46.096460Z","shell.execute_reply.started":"2021-12-23T18:24:45.973805Z","shell.execute_reply":"2021-12-23T18:24:46.095138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Filtering out 2018-10-09 from dataset","metadata":{}},{"cell_type":"code","source":"tr18['date'] = pd.DatetimeIndex(tr18['date'])\nrslt_df = tr18[tr18['date'] == '2018-10-09']\nprint(rslt_df.head())","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:24:46.098414Z","iopub.execute_input":"2021-12-23T18:24:46.098819Z","iopub.status.idle":"2021-12-23T18:24:49.464928Z","shell.execute_reply.started":"2021-12-23T18:24:46.098769Z","shell.execute_reply":"2021-12-23T18:24:49.463951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Animation play for the date - 2018-10-09","metadata":{}},{"cell_type":"code","source":"fig = px.scatter(rslt_df, x=\"x\", y=\"y\", animation_frame=\"time\", color=\"team\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:24:49.466118Z","iopub.execute_input":"2021-12-23T18:24:49.466365Z","iopub.status.idle":"2021-12-23T18:25:02.765094Z","shell.execute_reply.started":"2021-12-23T18:24:49.466335Z","shell.execute_reply":"2021-12-23T18:25:02.764077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Filtering out 2018-11-30 from dataset","metadata":{}},{"cell_type":"code","source":"rslt_df = tr18[tr18['date'] == '2018-11-30']\nprint(rslt_df.head())","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:25:02.774961Z","iopub.execute_input":"2021-12-23T18:25:02.775292Z","iopub.status.idle":"2021-12-23T18:25:02.830762Z","shell.execute_reply.started":"2021-12-23T18:25:02.775255Z","shell.execute_reply":"2021-12-23T18:25:02.830116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Animation play for the date - 2018-11-30","metadata":{}},{"cell_type":"code","source":"fig = px.scatter(rslt_df, x=\"x\", y=\"y\", animation_frame=\"time\", color=\"team\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:25:02.831861Z","iopub.execute_input":"2021-12-23T18:25:02.832579Z","iopub.status.idle":"2021-12-23T18:25:19.586069Z","shell.execute_reply.started":"2021-12-23T18:25:02.832533Z","shell.execute_reply":"2021-12-23T18:25:19.585194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizing football pitch using matplotlib","metadata":{}},{"cell_type":"markdown","source":"**Creating function to draw football field**","metadata":{}},{"cell_type":"code","source":"def drawfield():\n    \n    # Creating a new figure\n    plt.figure(figsize = (24,10))\n\n    # Getting current axis\n    ax = plt.gca()\n\n    # Creating a rectangle for the entire figure size and filling it with grass colour\n    ax.add_patch(patches.Rectangle((0, 0), 24, 10, facecolor='#3f995b'))\n\n    # Creating vertical lines\n    for i in range(1, 22):\n        plt.axvline(x = i+1, color='white')\n\n    # Adding text to vertical lines\n    k = 10\n    for j in range(4, 22):\n        if j%2 == 0 and j <= 12:\n            #count = k + 10\n            plt.text(x = j - 0.25, y = 0.85, s = k, color = \"white\", size = 20, weight = \"bold\")\n            plt.text(x = j - 0.25, y = 0.125, s = k, color = \"white\", size = 20, weight = \"bold\", rotation=180)\n            k = k + 10\n        if j%2 == 0 and j > 11:\n            k = k - 10\n            plt.text(x = j - 0.25, y = 0.85, s = k, color = \"white\", size = 20, weight = \"bold\")\n            plt.text(x = j - 0.25, y = 0.125, s = k, color = \"white\", size = 20, weight = \"bold\", rotation=180)\n\n    # Adding yard markers in between the vertical lines\n    for l in range(2, 22):\n        plt.text(x = l, y = 0.95, s = \" |||| \", color = \"white\", size = 25, weight = \"bold\")\n        plt.text(x = l, y = 0.65, s = \" |||| \", color = \"white\", size = 25, weight = \"bold\")\n        plt.text(x = l, y = 0.325, s = \" |||| \", color = \"white\", size = 25, weight = \"bold\")\n        plt.text(x = l, y = 0.025, s = \" |||| \", color = \"white\", size = 25, weight = \"bold\")\n    \n    # Adding home end zone\n    ax.add_patch(patches.Rectangle((0, 0), 2, 10, facecolor='#0064dc'))\n    plt.text(x = 0.5, y = 0.37, s = \"HOME\",color = \"white\", size = 50, weight=\"bold\", rotation=90)\n\n    # Adding away end zone\n    ax.add_patch(patches.Rectangle((22, 0), 2, 10, facecolor='#c80014'))\n    plt.text(x = 22.5, y = 0.37, s = \"AWAY\",color = \"white\", size = 50, weight=\"bold\", rotation=270)\n    \n    # Adding spot points\n    plt.axvline(x = 2.4, ymin = 0.45, ymax = 0.55, color = \"white\")\n    plt.axvline(x = 21.6, ymin = 0.45, ymax = 0.55, color = \"white\")\n\n    # Adding goalposts\n    plt.axvline(x = 0, ymin = 0.425, ymax = 0.575, color = \"yellow\", linewidth = 10)\n    plt.axvline(x = 24, ymin = 0.425, ymax = 0.575, color = \"yellow\", linewidth = 10)\n\n    # Removing X and Y axes from the plot\n    plt.axis('off')\n\n    # Displaying plot\n    plt.show()\n    \ndrawfield()","metadata":{"execution":{"iopub.status.busy":"2021-12-23T18:25:19.587937Z","iopub.execute_input":"2021-12-23T18:25:19.588777Z","iopub.status.idle":"2021-12-23T18:25:20.176174Z","shell.execute_reply.started":"2021-12-23T18:25:19.588731Z","shell.execute_reply":"2021-12-23T18:25:20.175266Z"},"trusted":true},"execution_count":null,"outputs":[]}]}