{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"#                                            NFL BIG DATA BOWL 2022\n\n\n                                                     TEAM : Data Dictators\n                                                     \n                                                            Members\n                                                      \n                                                   1. Soumya Sourav Behera (Leader)\n                                                   2. J. Venkateswar Achary","metadata":{}},{"cell_type":"markdown","source":"# Importing Necessary Libraries","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt \nimport matplotlib.patches as patches\nimport seaborn as sns\nfrom ipywidgets import interact\nimport plotly.express as px\nimport plotly.graph_objects as go\nimport plotly.io as pio","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:27:58.794355Z","iopub.execute_input":"2022-01-03T07:27:58.794667Z","iopub.status.idle":"2022-01-03T07:27:58.799566Z","shell.execute_reply.started":"2022-01-03T07:27:58.794637Z","shell.execute_reply":"2022-01-03T07:27:58.798933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# PFF Scouting data","metadata":{}},{"cell_type":"code","source":"#loading pffscouting data\npffs = pd.read_csv('../input/nfl-big-data-bowl-2022/PFFScoutingData.csv')\n#checking its shape\npffs.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:27:58.800905Z","iopub.execute_input":"2022-01-03T07:27:58.801240Z","iopub.status.idle":"2022-01-03T07:27:58.903842Z","shell.execute_reply.started":"2022-01-03T07:27:58.801212Z","shell.execute_reply":"2022-01-03T07:27:58.903177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking 1st 5 rows\npffs.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:27:58.904844Z","iopub.execute_input":"2022-01-03T07:27:58.905162Z","iopub.status.idle":"2022-01-03T07:27:58.934185Z","shell.execute_reply.started":"2022-01-03T07:27:58.905137Z","shell.execute_reply":"2022-01-03T07:27:58.933551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking summary\npffs.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:27:58.935419Z","iopub.execute_input":"2022-01-03T07:27:58.935775Z","iopub.status.idle":"2022-01-03T07:27:58.972713Z","shell.execute_reply.started":"2022-01-03T07:27:58.935743Z","shell.execute_reply":"2022-01-03T07:27:58.972011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking for null values\npffs.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:27:58.974507Z","iopub.execute_input":"2022-01-03T07:27:58.974879Z","iopub.status.idle":"2022-01-03T07:27:58.995535Z","shell.execute_reply.started":"2022-01-03T07:27:58.974848Z","shell.execute_reply":"2022-01-03T07:27:58.994818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# unique games played can be determined by the game ID.\npffs.gameId.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:27:58.996561Z","iopub.execute_input":"2022-01-03T07:27:58.996886Z","iopub.status.idle":"2022-01-03T07:27:59.005087Z","shell.execute_reply.started":"2022-01-03T07:27:58.996859Z","shell.execute_reply":"2022-01-03T07:27:59.004457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Play identifier, not unique across games (numeric)\npffs.playId.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:27:59.006132Z","iopub.execute_input":"2022-01-03T07:27:59.006513Z","iopub.status.idle":"2022-01-03T07:27:59.019118Z","shell.execute_reply.started":"2022-01-03T07:27:59.006483Z","shell.execute_reply":"2022-01-03T07:27:59.018143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# counting different types of snap details\nprint(\"Unique NFL Snap Details values and their counts :\")\npffs_sd = pffs.pivot_table(index = ['snapDetail'], aggfunc = 'size') \npffs_sd = pffs_sd.reset_index()\npffs_sd.columns= [\"Snap Details\", \"Counts\"]\npffs_sd = pffs_sd.sort_values(\"Counts\", ascending = False)\nprint(pffs_sd)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:27:59.021115Z","iopub.execute_input":"2022-01-03T07:27:59.021693Z","iopub.status.idle":"2022-01-03T07:27:59.037742Z","shell.execute_reply.started":"2022-01-03T07:27:59.021649Z","shell.execute_reply":"2022-01-03T07:27:59.036735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"px.bar(pffs_sd, x=\"Snap Details\", y=\"Counts\", title=\"Distinct Count Of Snap Details\", color=\"Snap Details\")","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:27:59.038917Z","iopub.execute_input":"2022-01-03T07:27:59.039221Z","iopub.status.idle":"2022-01-03T07:28:00.234667Z","shell.execute_reply.started":"2022-01-03T07:27:59.039178Z","shell.execute_reply":"2022-01-03T07:28:00.233834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n- Most shot played is perfect with great accuracy(ok).","metadata":{}},{"cell_type":"code","source":"fig = px.scatter(pffs, x='hangTime', y='operationTime')\n\nfig.update_traces(marker=dict(size=6,\n                              line=dict(width=0.5,\n                                        color='DarkSlateGrey')),\n                  selector=dict(mode='markers'))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:00.237431Z","iopub.execute_input":"2022-01-03T07:28:00.237680Z","iopub.status.idle":"2022-01-03T07:28:00.393357Z","shell.execute_reply.started":"2022-01-03T07:28:00.237653Z","shell.execute_reply":"2022-01-03T07:28:00.392482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation:*\n1. Operation time is lies between 1.5 sec to 2.5 sec.\n2. Hang time of the player is varies from 2 to 5 seconds.","metadata":{}},{"cell_type":"code","source":"# Counting different types of kick played\nKick_type = pffs['kickType'].value_counts().reset_index()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:00.396928Z","iopub.execute_input":"2022-01-03T07:28:00.397444Z","iopub.status.idle":"2022-01-03T07:28:00.405309Z","shell.execute_reply.started":"2022-01-03T07:28:00.397399Z","shell.execute_reply":"2022-01-03T07:28:00.404049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Kick_type.rename(columns = {'index' : 'Type_of_kick', 'kickType' : 'Count'}, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:00.406695Z","iopub.execute_input":"2022-01-03T07:28:00.406990Z","iopub.status.idle":"2022-01-03T07:28:00.419354Z","shell.execute_reply.started":"2022-01-03T07:28:00.406957Z","shell.execute_reply":"2022-01-03T07:28:00.418537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Kick_type","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:00.420488Z","iopub.execute_input":"2022-01-03T07:28:00.421131Z","iopub.status.idle":"2022-01-03T07:28:00.437581Z","shell.execute_reply.started":"2022-01-03T07:28:00.421100Z","shell.execute_reply":"2022-01-03T07:28:00.436651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating and printing of a pie chart of different types of kick count played in the game\nfig= px.pie(Kick_type, values='Count', names='Type_of_kick', title='count of Kick Type',width=800,height=600)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:00.438753Z","iopub.execute_input":"2022-01-03T07:28:00.439030Z","iopub.status.idle":"2022-01-03T07:28:00.501532Z","shell.execute_reply.started":"2022-01-03T07:28:00.439000Z","shell.execute_reply":"2022-01-03T07:28:00.500710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation:*\n1. More than half of the shots played is normal deep kick with decent hang time(most played kick) denoted by D.\n1. Surprise kick are most rare as the name suggested.","metadata":{}},{"cell_type":"markdown","source":"# Players Data","metadata":{}},{"cell_type":"code","source":"#loading the players dataset\nplayers = pd.read_csv('../input/nfl-big-data-bowl-2022/players.csv')\n\n#checking the shape of players dataset\nplayers.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:00.502981Z","iopub.execute_input":"2022-01-03T07:28:00.503741Z","iopub.status.idle":"2022-01-03T07:28:00.525284Z","shell.execute_reply.started":"2022-01-03T07:28:00.503708Z","shell.execute_reply":"2022-01-03T07:28:00.524429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking the first 5 rows of the dataset\nplayers.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:00.526493Z","iopub.execute_input":"2022-01-03T07:28:00.526706Z","iopub.status.idle":"2022-01-03T07:28:00.540685Z","shell.execute_reply.started":"2022-01-03T07:28:00.526681Z","shell.execute_reply":"2022-01-03T07:28:00.539749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking the summary of the dataset\nplayers.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:00.542183Z","iopub.execute_input":"2022-01-03T07:28:00.542459Z","iopub.status.idle":"2022-01-03T07:28:00.561501Z","shell.execute_reply.started":"2022-01-03T07:28:00.542424Z","shell.execute_reply":"2022-01-03T07:28:00.560374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. Null values are present in 'birthDate', 'collegeName' columns\n2. Height column is in object Dtype\n3. birthDate in in object Dtype","metadata":{}},{"cell_type":"code","source":"#dropping the null values present in the dataset\nplayers = players.dropna()\n\n#rechecking the shape of the dataset after dropping the null values\nplayers.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:00.562838Z","iopub.execute_input":"2022-01-03T07:28:00.563466Z","iopub.status.idle":"2022-01-03T07:28:00.578455Z","shell.execute_reply.started":"2022-01-03T07:28:00.563426Z","shell.execute_reply":"2022-01-03T07:28:00.577444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking the counts of unique values\nplayers['height'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:00.580213Z","iopub.execute_input":"2022-01-03T07:28:00.580453Z","iopub.status.idle":"2022-01-03T07:28:00.589485Z","shell.execute_reply.started":"2022-01-03T07:28:00.580426Z","shell.execute_reply":"2022-01-03T07:28:00.588787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n\n1. Some of the values are in feet-inch format and some are in inch format","metadata":{}},{"cell_type":"code","source":"#Parsing object as string and splitting height values into feet and inch\nheight_new = players[\"height\"].str.split(\"-\", n = 1, expand = True)\nheight_new.columns = ['Feet', 'Inch']\nplayers[\"height_feet\"] = pd.to_numeric(height_new[\"Feet\"])\nplayers[\"height_inch\"] = pd.to_numeric(height_new[\"Inch\"])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:00.590329Z","iopub.execute_input":"2022-01-03T07:28:00.590983Z","iopub.status.idle":"2022-01-03T07:28:00.608118Z","shell.execute_reply.started":"2022-01-03T07:28:00.590951Z","shell.execute_reply":"2022-01-03T07:28:00.607175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Column - height_feet\nfor i in players[\"height_feet\"]:\n    if i > 7:\n        j = 0.0833333 * i\n        players[\"height_feet\"].replace({i : j}, inplace=True)\n        \n# Column - height_inch\nplayers[\"height_inch\"] = 0.0833333 * players[\"height_inch\"]\n\n# Converting Nan values to zero in height_inch column \nfor i in players[\"height_inch\"]:\n    players[\"height_inch\"] = players[\"height_inch\"].fillna(0)\n\n# combining two height columns\nplayers[\"height_feet\"] = players[\"height_feet\"] + players[\"height_inch\"]\n\n\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:00.609065Z","iopub.execute_input":"2022-01-03T07:28:00.609530Z","iopub.status.idle":"2022-01-03T07:28:01.141929Z","shell.execute_reply.started":"2022-01-03T07:28:00.609494Z","shell.execute_reply":"2022-01-03T07:28:01.141064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#dropping height and height_inch column\nplayers = players.drop(['height','height_inch'], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:01.143234Z","iopub.execute_input":"2022-01-03T07:28:01.143499Z","iopub.status.idle":"2022-01-03T07:28:01.150612Z","shell.execute_reply.started":"2022-01-03T07:28:01.143467Z","shell.execute_reply":"2022-01-03T07:28:01.149594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#rechecking top 5 rows\nplayers.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:01.151916Z","iopub.execute_input":"2022-01-03T07:28:01.152244Z","iopub.status.idle":"2022-01-03T07:28:01.173950Z","shell.execute_reply.started":"2022-01-03T07:28:01.152199Z","shell.execute_reply":"2022-01-03T07:28:01.172870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#rounding up players height upto 1 decimal\nplayers['height_feet'] = players['height_feet'].round(decimals = 1)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:01.177374Z","iopub.execute_input":"2022-01-03T07:28:01.178181Z","iopub.status.idle":"2022-01-03T07:28:01.185440Z","shell.execute_reply.started":"2022-01-03T07:28:01.178140Z","shell.execute_reply":"2022-01-03T07:28:01.184470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#convering dtype of birthdate object \nplayers[\"birthDate\"] = pd.to_datetime(players[\"birthDate\"])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:01.187003Z","iopub.execute_input":"2022-01-03T07:28:01.187525Z","iopub.status.idle":"2022-01-03T07:28:01.201426Z","shell.execute_reply.started":"2022-01-03T07:28:01.187472Z","shell.execute_reply":"2022-01-03T07:28:01.200680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#creating a 'birthYear' column\nplayers['birthYear'] = pd.DatetimeIndex(players['birthDate']).year\nplayers[\"birthYear\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:01.202690Z","iopub.execute_input":"2022-01-03T07:28:01.202961Z","iopub.status.idle":"2022-01-03T07:28:01.224822Z","shell.execute_reply.started":"2022-01-03T07:28:01.202931Z","shell.execute_reply":"2022-01-03T07:28:01.223885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#rechecking the dataset\nplayers.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:01.226147Z","iopub.execute_input":"2022-01-03T07:28:01.226588Z","iopub.status.idle":"2022-01-03T07:28:01.240753Z","shell.execute_reply.started":"2022-01-03T07:28:01.226541Z","shell.execute_reply":"2022-01-03T07:28:01.239975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#exploring statistical informations\nplayers.describe()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:01.245474Z","iopub.execute_input":"2022-01-03T07:28:01.245884Z","iopub.status.idle":"2022-01-03T07:28:01.271327Z","shell.execute_reply.started":"2022-01-03T07:28:01.245835Z","shell.execute_reply":"2022-01-03T07:28:01.270669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking for outliers\nfor i in players.columns:\n    fig = px.box(players, x=i,  width=800, height=400) \n    fig.show()","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-01-03T07:28:01.272339Z","iopub.execute_input":"2022-01-03T07:28:01.273168Z","iopub.status.idle":"2022-01-03T07:28:01.779109Z","shell.execute_reply.started":"2022-01-03T07:28:01.273113Z","shell.execute_reply":"2022-01-03T07:28:01.778432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Vizualizing player's height by histogram\npx.histogram(players, x=\"height_feet\", title=\"Player's Height In Feet\", nbins=10, color_discrete_sequence=[\"coral\"])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:01.779944Z","iopub.execute_input":"2022-01-03T07:28:01.780193Z","iopub.status.idle":"2022-01-03T07:28:01.866772Z","shell.execute_reply.started":"2022-01-03T07:28:01.780140Z","shell.execute_reply":"2022-01-03T07:28:01.865741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. Most of the players are in height of 6.2-6.3\n2. only 6 people are below 5.5ft","metadata":{}},{"cell_type":"code","source":"# Vizualizing birthyear by histogram plot\npx.histogram(players, x=\"birthYear\", title=\"Birth Year Of Players\", color_discrete_sequence=[\"darkred\"])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:01.868231Z","iopub.execute_input":"2022-01-03T07:28:01.868566Z","iopub.status.idle":"2022-01-03T07:28:01.936119Z","shell.execute_reply.started":"2022-01-03T07:28:01.868535Z","shell.execute_reply":"2022-01-03T07:28:01.935358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. only 7 players have birth year in 1972-1980\n2. Birthyear of 1999 players are the younger ones","metadata":{}},{"cell_type":"code","source":"# Creating Histogram plot to vizualize weight of the players\npx.histogram(players, x=\"weight\", nbins=10,title=\"Player's Weight In lbs (pounds)\", color_discrete_sequence=[\"darkblue\"])\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:01.937474Z","iopub.execute_input":"2022-01-03T07:28:01.937763Z","iopub.status.idle":"2022-01-03T07:28:02.002842Z","shell.execute_reply.started":"2022-01-03T07:28:01.937731Z","shell.execute_reply":"2022-01-03T07:28:02.001905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. Maximum of players are in weight of 200-249lbs","metadata":{}},{"cell_type":"code","source":"print(\"Unique college names and their counts : \")\ncollege_names = players.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":"2022-01-03T07:28:02.003999Z","iopub.execute_input":"2022-01-03T07:28:02.004731Z","iopub.status.idle":"2022-01-03T07:28:02.019292Z","shell.execute_reply.started":"2022-01-03T07:28:02.004665Z","shell.execute_reply":"2022-01-03T07:28:02.018569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Tree map plot for vizualizing colleges\npx.treemap(college_names, path=['College Names'], values='Counts', color='Counts', title=\"Arrangement Of Colleges From Highest To Lowest Number Of Players\")\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.020867Z","iopub.execute_input":"2022-01-03T07:28:02.021345Z","iopub.status.idle":"2022-01-03T07:28:02.265090Z","shell.execute_reply.started":"2022-01-03T07:28:02.021312Z","shell.execute_reply":"2022-01-03T07:28:02.264211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#creating dataframe for top10 colleges\ntop_colleges = college_names[0:10]","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.266531Z","iopub.execute_input":"2022-01-03T07:28:02.266862Z","iopub.status.idle":"2022-01-03T07:28:02.271655Z","shell.execute_reply.started":"2022-01-03T07:28:02.266823Z","shell.execute_reply":"2022-01-03T07:28:02.270572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#vizualizing top10 collleges using piechart\npx.pie(top_colleges, values='Counts', names='College Names', title='Top 10 Colleges Having Higher Number Of Players')\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.273137Z","iopub.execute_input":"2022-01-03T07:28:02.274025Z","iopub.status.idle":"2022-01-03T07:28:02.325870Z","shell.execute_reply.started":"2022-01-03T07:28:02.273976Z","shell.execute_reply":"2022-01-03T07:28:02.324946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*:\n1. 13.5% (most) players are from Alabama college","metadata":{}},{"cell_type":"code","source":"#replacing abbrevated words with keywords\nplayers[\"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)\nplayers[\"Position\"]","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.326947Z","iopub.execute_input":"2022-01-03T07:28:02.327169Z","iopub.status.idle":"2022-01-03T07:28:02.345797Z","shell.execute_reply.started":"2022-01-03T07:28:02.327142Z","shell.execute_reply":"2022-01-03T07:28:02.345181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Unique position values and their counts :\")\npos_val = players.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":"2022-01-03T07:28:02.346713Z","iopub.execute_input":"2022-01-03T07:28:02.347401Z","iopub.status.idle":"2022-01-03T07:28:02.370197Z","shell.execute_reply.started":"2022-01-03T07:28:02.347351Z","shell.execute_reply":"2022-01-03T07:28:02.369223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#  Creating Bar plot to vizualize position\npx.bar(pos_val, x=\"Positions\", y=\"Counts\", title=\"Arrangement Of Positions From Frequently Used To Least Used\", color=pos_val[\"Counts\"])\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.371689Z","iopub.execute_input":"2022-01-03T07:28:02.372302Z","iopub.status.idle":"2022-01-03T07:28:02.440648Z","shell.execute_reply.started":"2022-01-03T07:28:02.372266Z","shell.execute_reply":"2022-01-03T07:28:02.439844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. We have most players available for wide reciever and corner back position\n2. Very less number of players are for half bacj, safety, offensive guard position","metadata":{}},{"cell_type":"code","source":"@interact\ndef summary(Positions = list(players['Position'].value_counts().index)):\n    x = players[players['Position']== Positions]\n    z = players.drop(['nflId','collegeName','displayName','Position','birthDate','birthYear'],axis=1)\n    for i in z:\n        print('Minimum', i, x[i].min())\n        print('Average', i, x[i].mean())\n        print('Maximum', i, x[i].max())\n        print('--------------------------------------------------')","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.442522Z","iopub.execute_input":"2022-01-03T07:28:02.442842Z","iopub.status.idle":"2022-01-03T07:28:02.486740Z","shell.execute_reply.started":"2022-01-03T07:28:02.442799Z","shell.execute_reply":"2022-01-03T07:28:02.485929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Positions which requires tall players', players[players['height_feet']>6.5]['Position'].unique())\nprint('Position which requires players having high in weight:', players[players['weight']>350]['Position'].unique())","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.488169Z","iopub.execute_input":"2022-01-03T07:28:02.488408Z","iopub.status.idle":"2022-01-03T07:28:02.497343Z","shell.execute_reply.started":"2022-01-03T07:28:02.488364Z","shell.execute_reply":"2022-01-03T07:28:02.496418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Games Data","metadata":{}},{"cell_type":"code","source":"#loading the dataset\ngames = pd.read_csv('../input/nfl-big-data-bowl-2022/games.csv')\n\n#checking the shape of the dataset\ngames.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.498348Z","iopub.execute_input":"2022-01-03T07:28:02.498858Z","iopub.status.idle":"2022-01-03T07:28:02.517491Z","shell.execute_reply.started":"2022-01-03T07:28:02.498824Z","shell.execute_reply":"2022-01-03T07:28:02.516725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking first five rows\ngames.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.518437Z","iopub.execute_input":"2022-01-03T07:28:02.519095Z","iopub.status.idle":"2022-01-03T07:28:02.531152Z","shell.execute_reply.started":"2022-01-03T07:28:02.519061Z","shell.execute_reply":"2022-01-03T07:28:02.530486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Concating elements of columns gameDate and gameTimeEastern\ngames['date']=games.gameDate.str.cat(games.gameTimeEastern)\ngames.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.532147Z","iopub.execute_input":"2022-01-03T07:28:02.532587Z","iopub.status.idle":"2022-01-03T07:28:02.547770Z","shell.execute_reply.started":"2022-01-03T07:28:02.532534Z","shell.execute_reply":"2022-01-03T07:28:02.547108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking the summary\ngames.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.548832Z","iopub.execute_input":"2022-01-03T07:28:02.549200Z","iopub.status.idle":"2022-01-03T07:28:02.567791Z","shell.execute_reply.started":"2022-01-03T07:28:02.549169Z","shell.execute_reply":"2022-01-03T07:28:02.567121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. \"gameDate\" and \"date\" is in object type ","metadata":{}},{"cell_type":"code","source":"# converting the object to datetime data type \ngames['date'] = pd.to_datetime(games['date'], format=\"%m/%d/%Y%H:%M:%S\")","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.568875Z","iopub.execute_input":"2022-01-03T07:28:02.569278Z","iopub.status.idle":"2022-01-03T07:28:02.582905Z","shell.execute_reply.started":"2022-01-03T07:28:02.569237Z","shell.execute_reply":"2022-01-03T07:28:02.582197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# creating a table for number of games played in particular season\nSeason = games.pivot_table(index =['season'],aggfunc ='size')\nSeason = Season.reset_index()\nSeason.columns =['Seasons','Total games']\nSeason = Season.sort_values('Total games',ascending = False)\nprint(Season)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.583949Z","iopub.execute_input":"2022-01-03T07:28:02.584562Z","iopub.status.idle":"2022-01-03T07:28:02.598496Z","shell.execute_reply.started":"2022-01-03T07:28:02.584522Z","shell.execute_reply":"2022-01-03T07:28:02.597878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#creating a barplot of total game count vs seasons using plotly \nfig = px.pie(Season,names= 'Seasons',values ='Total games',title = 'SEASONS',width=500, height=500)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.599528Z","iopub.execute_input":"2022-01-03T07:28:02.599888Z","iopub.status.idle":"2022-01-03T07:28:02.648359Z","shell.execute_reply.started":"2022-01-03T07:28:02.599850Z","shell.execute_reply":"2022-01-03T07:28:02.647480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. Highest games are played in 2020.\n2. Lowest in 2018.\n3. Although they are almost equal to each other.","metadata":{}},{"cell_type":"code","source":"# Creating a table for Unique NFL weeks and their counts\nprint(\"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":"2022-01-03T07:28:02.649856Z","iopub.execute_input":"2022-01-03T07:28:02.650296Z","iopub.status.idle":"2022-01-03T07:28:02.661352Z","shell.execute_reply.started":"2022-01-03T07:28:02.650259Z","shell.execute_reply":"2022-01-03T07:28:02.660690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot of Weeks vs Counts\npx.bar(g_week, x=\"Weeks\", y=\"Counts\", title=\"NFL Weeks\", color=\"Weeks\")","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.662536Z","iopub.execute_input":"2022-01-03T07:28:02.662899Z","iopub.status.idle":"2022-01-03T07:28:02.727815Z","shell.execute_reply.started":"2022-01-03T07:28:02.662863Z","shell.execute_reply":"2022-01-03T07:28:02.726934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. Trend of frequency of counts per week is first high then decreased significantly till week 11(41)\n2. After 11th week counts again increased to highest counts(48).","metadata":{}},{"cell_type":"code","source":"# Creating a table for Unique NFL dates and their Counts\nprint(\"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":"2022-01-03T07:28:02.729252Z","iopub.execute_input":"2022-01-03T07:28:02.729578Z","iopub.status.idle":"2022-01-03T07:28:02.745706Z","shell.execute_reply.started":"2022-01-03T07:28:02.729503Z","shell.execute_reply":"2022-01-03T07:28:02.744470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot\npx.bar(g_date, x=\"Date\", y=\"Counts\", title='Dates On Which NFL Events Occurred', color=\"Counts\")\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.746991Z","iopub.execute_input":"2022-01-03T07:28:02.748595Z","iopub.status.idle":"2022-01-03T07:28:02.817268Z","shell.execute_reply.started":"2022-01-03T07:28:02.748547Z","shell.execute_reply":"2022-01-03T07:28:02.816613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. Most games played in only three days. one is 01/03/2021 , 12/29/2018 ,12/30/2018\n2. Most of the days (half of total days the total events organized) contains only a single game.","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":"2022-01-03T07:28:02.818246Z","iopub.execute_input":"2022-01-03T07:28:02.819222Z","iopub.status.idle":"2022-01-03T07:28:02.829125Z","shell.execute_reply.started":"2022-01-03T07:28:02.819185Z","shell.execute_reply":"2022-01-03T07:28:02.828107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games['gameYear'] = pd.DatetimeIndex(games['gameDate']).year\nprint(games[\"gameYear\"])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.831751Z","iopub.execute_input":"2022-01-03T07:28:02.832017Z","iopub.status.idle":"2022-01-03T07:28:02.843529Z","shell.execute_reply.started":"2022-01-03T07:28:02.831989Z","shell.execute_reply":"2022-01-03T07:28:02.842316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating a table for different years vs total games played on those years to check the correctness of data given for seasons\nprint(\"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":"2022-01-03T07:28:02.845059Z","iopub.execute_input":"2022-01-03T07:28:02.846084Z","iopub.status.idle":"2022-01-03T07:28:02.867585Z","shell.execute_reply.started":"2022-01-03T07:28:02.846025Z","shell.execute_reply":"2022-01-03T07:28:02.866517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot\npx.bar(g_year, x=\"Year\", y=\"Counts\", title=\"Distinct Count Of NFL Event Years\", color=\"Year\",width=800, height=600)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.869325Z","iopub.execute_input":"2022-01-03T07:28:02.870375Z","iopub.status.idle":"2022-01-03T07:28:02.935250Z","shell.execute_reply.started":"2022-01-03T07:28:02.870327Z","shell.execute_reply":"2022-01-03T07:28:02.934376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. In some rows season and date are not accordingly matched as games are conducted in 2021 but there is no season information given to those dates.\n2. This can conclude that* some games of season 2020 is conducted in 2021* due to some problem or crisis most probably CoVID-19.","metadata":{}},{"cell_type":"code","source":"games[\"gameMonthName\"] = games[\"gameDate\"].dt.month_name()\nprint(games[\"gameMonthName\"])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.936646Z","iopub.execute_input":"2022-01-03T07:28:02.936935Z","iopub.status.idle":"2022-01-03T07:28:02.945877Z","shell.execute_reply.started":"2022-01-03T07:28:02.936901Z","shell.execute_reply":"2022-01-03T07:28:02.945018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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":"2022-01-03T07:28:02.947675Z","iopub.execute_input":"2022-01-03T07:28:02.948264Z","iopub.status.idle":"2022-01-03T07:28:02.962554Z","shell.execute_reply.started":"2022-01-03T07:28:02.948214Z","shell.execute_reply":"2022-01-03T07:28:02.961257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot\npx.bar(g_month, x=\"Month\", y=\"Counts\", title=\"Distinct Count Of NFL Event Months\", color=\"Month\",width=900, height=600)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:02.963740Z","iopub.execute_input":"2022-01-03T07:28:02.964988Z","iopub.status.idle":"2022-01-03T07:28:03.044745Z","shell.execute_reply.started":"2022-01-03T07:28:02.964944Z","shell.execute_reply":"2022-01-03T07:28:03.043901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation:*\n1. In december most games are played.\n2. Least games are played in january.(could be the games played due to some problem and played in other year not according to the season.)","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":"2022-01-03T07:28:03.046622Z","iopub.execute_input":"2022-01-03T07:28:03.047182Z","iopub.status.idle":"2022-01-03T07:28:03.060417Z","shell.execute_reply.started":"2022-01-03T07:28:03.047135Z","shell.execute_reply":"2022-01-03T07:28:03.059560Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot\npx.bar(g_time, x=\"Time\", y=\"Counts\", title=\"Distinct Count Of NFL Event Timings\", color=\"Counts\",width=800, height=600)\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:03.062484Z","iopub.execute_input":"2022-01-03T07:28:03.065436Z","iopub.status.idle":"2022-01-03T07:28:03.266054Z","shell.execute_reply.started":"2022-01-03T07:28:03.065366Z","shell.execute_reply":"2022-01-03T07:28:03.265172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. Most of the games are played at 1pm.\n2. From which we can conclude that the game is heavily played and enjoyed in afternoon.(NO GAMES PLAYED IN MORNING SESSION)","metadata":{}},{"cell_type":"markdown","source":"# Plays Data","metadata":{}},{"cell_type":"code","source":"#loading dataset\npd.pandas.set_option('display.max_columns', None)\nplays = pd.read_csv('../input/nfl-big-data-bowl-2022/plays.csv')","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:03.267066Z","iopub.execute_input":"2022-01-03T07:28:03.267305Z","iopub.status.idle":"2022-01-03T07:28:03.403647Z","shell.execute_reply.started":"2022-01-03T07:28:03.267278Z","shell.execute_reply":"2022-01-03T07:28:03.402585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking shape\nplays.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:03.404755Z","iopub.execute_input":"2022-01-03T07:28:03.405463Z","iopub.status.idle":"2022-01-03T07:28:03.410796Z","shell.execute_reply.started":"2022-01-03T07:28:03.405426Z","shell.execute_reply":"2022-01-03T07:28:03.409895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking top 5 rows\nplays.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:03.412120Z","iopub.execute_input":"2022-01-03T07:28:03.412425Z","iopub.status.idle":"2022-01-03T07:28:03.442218Z","shell.execute_reply.started":"2022-01-03T07:28:03.412371Z","shell.execute_reply":"2022-01-03T07:28:03.441610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking summary of the dataset\nplays.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:03.443231Z","iopub.execute_input":"2022-01-03T07:28:03.443596Z","iopub.status.idle":"2022-01-03T07:28:03.466577Z","shell.execute_reply.started":"2022-01-03T07:28:03.443561Z","shell.execute_reply":"2022-01-03T07:28:03.465640Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking for null values\nplays.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:03.468120Z","iopub.execute_input":"2022-01-03T07:28:03.468514Z","iopub.status.idle":"2022-01-03T07:28:03.488152Z","shell.execute_reply.started":"2022-01-03T07:28:03.468473Z","shell.execute_reply":"2022-01-03T07:28:03.487239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking statistical distibutions\nplays.describe()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:03.489161Z","iopub.execute_input":"2022-01-03T07:28:03.489789Z","iopub.status.idle":"2022-01-03T07:28:03.551236Z","shell.execute_reply.started":"2022-01-03T07:28:03.489756Z","shell.execute_reply":"2022-01-03T07:28:03.550486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#plotting a correlation map\nfig=plt.figure(figsize=(14,10))\ncorr=plays.corr('pearson')\nsns.heatmap(corr,cmap='RdBu_r',annot=True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:03.552320Z","iopub.execute_input":"2022-01-03T07:28:03.552686Z","iopub.status.idle":"2022-01-03T07:28:04.826118Z","shell.execute_reply.started":"2022-01-03T07:28:03.552658Z","shell.execute_reply":"2022-01-03T07:28:04.825521Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. PlayResult -vely correlated with kickReturnYardage and +vely correlated with kicklength, penaltyYards, yardlineNumber.\n2. kickReturnYardage is -vely correlated with down, yardsToGo and +vely correlated with kickLength\n3. kickLength is -vely correlated with down, yardsToGo\n4. preSnapVisitorScore is +vely correlated with preSnapHomeScore and quarter","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL game quarter values and their counts :\")\nplay_qrtr = plays.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":"2022-01-03T07:28:04.827313Z","iopub.execute_input":"2022-01-03T07:28:04.827710Z","iopub.status.idle":"2022-01-03T07:28:04.839320Z","shell.execute_reply.started":"2022-01-03T07:28:04.827657Z","shell.execute_reply":"2022-01-03T07:28:04.838049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot to vizualize quarter\npx.bar(play_qrtr, x=\"Quarter\", y=\"Counts\", title=\"Distinct Count Of NFL Game Quarters\", color=\"Quarter\")\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:04.840944Z","iopub.execute_input":"2022-01-03T07:28:04.841780Z","iopub.status.idle":"2022-01-03T07:28:04.919723Z","shell.execute_reply.started":"2022-01-03T07:28:04.841732Z","shell.execute_reply":"2022-01-03T07:28:04.918465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. Quarter 5 have too much less counts as compared to other quarter","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL game downs and their counts :\")\ng_down = plays.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":"2022-01-03T07:28:04.921407Z","iopub.execute_input":"2022-01-03T07:28:04.921876Z","iopub.status.idle":"2022-01-03T07:28:04.936932Z","shell.execute_reply.started":"2022-01-03T07:28:04.921746Z","shell.execute_reply":"2022-01-03T07:28:04.936007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot to vizualize down\npx.bar(g_down, x=\"Down\", y=\"Counts\", title=\"Distinct Count Of NFL Game Downs\", color=\"Down\")\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:04.938620Z","iopub.execute_input":"2022-01-03T07:28:04.939148Z","iopub.status.idle":"2022-01-03T07:28:04.998991Z","shell.execute_reply.started":"2022-01-03T07:28:04.939114Z","shell.execute_reply":"2022-01-03T07:28:04.998021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Unique NFL yards to go and their counts :\")\ng_yards = plays.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":"2022-01-03T07:28:05.000685Z","iopub.execute_input":"2022-01-03T07:28:05.001052Z","iopub.status.idle":"2022-01-03T07:28:05.013998Z","shell.execute_reply.started":"2022-01-03T07:28:05.001004Z","shell.execute_reply":"2022-01-03T07:28:05.013042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot\npx.bar(g_yards, x=\"Yards To Go\", y=\"Counts\", title=\"Distinct Count Of Yards To Go In NFL Game\", color=\"Yards To Go\")\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:05.015558Z","iopub.execute_input":"2022-01-03T07:28:05.015850Z","iopub.status.idle":"2022-01-03T07:28:05.079462Z","shell.execute_reply.started":"2022-01-03T07:28:05.015808Z","shell.execute_reply":"2022-01-03T07:28:05.078468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plays[\"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)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:05.081081Z","iopub.execute_input":"2022-01-03T07:28:05.081469Z","iopub.status.idle":"2022-01-03T07:28:05.113186Z","shell.execute_reply.started":"2022-01-03T07:28:05.081428Z","shell.execute_reply":"2022-01-03T07:28:05.112157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Unique NFL possession teams and their counts :\")\np_team = plays.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":"2022-01-03T07:28:05.114585Z","iopub.execute_input":"2022-01-03T07:28:05.114893Z","iopub.status.idle":"2022-01-03T07:28:05.128825Z","shell.execute_reply.started":"2022-01-03T07:28:05.114854Z","shell.execute_reply":"2022-01-03T07:28:05.128041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot\npx.bar(p_team, x=\"Possession Team\", y=\"Counts\", title=\"Distinct Count Of NFL Possession Teams\", color=\"Counts\")","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:05.129871Z","iopub.execute_input":"2022-01-03T07:28:05.130656Z","iopub.status.idle":"2022-01-03T07:28:05.195061Z","shell.execute_reply.started":"2022-01-03T07:28:05.130620Z","shell.execute_reply":"2022-01-03T07:28:05.194434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. Las Vegas Raiders and Oakland Raiders have very low Possession team counts","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL special teams play type and their counts :\")\ngp_type = plays.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":"2022-01-03T07:28:05.196258Z","iopub.execute_input":"2022-01-03T07:28:05.196640Z","iopub.status.idle":"2022-01-03T07:28:05.208641Z","shell.execute_reply.started":"2022-01-03T07:28:05.196604Z","shell.execute_reply":"2022-01-03T07:28:05.207813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot\npx.bar(gp_type, x=\"Special Teams Play Type\", y=\"Counts\", title=\"Distinct Count Of NFL Special Teams Play Type\", color=\"Counts\")\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:05.218330Z","iopub.execute_input":"2022-01-03T07:28:05.218779Z","iopub.status.idle":"2022-01-03T07:28:05.283449Z","shell.execute_reply.started":"2022-01-03T07:28:05.218747Z","shell.execute_reply":"2022-01-03T07:28:05.282380Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. Kickoff playtype has highest counts (nearly 39%)\n2. Field goal has very low on count as compared to others","metadata":{}},{"cell_type":"code","source":"print(\"Unique NFL special teams result and their counts :\")\ngp_res = plays.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":"2022-01-03T07:28:05.284821Z","iopub.execute_input":"2022-01-03T07:28:05.285080Z","iopub.status.idle":"2022-01-03T07:28:05.299100Z","shell.execute_reply.started":"2022-01-03T07:28:05.285047Z","shell.execute_reply":"2022-01-03T07:28:05.298192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot\npx.bar(gp_res, x=\"Special Teams Result\", y=\"Counts\", title=\"Distinct Count Of NFL Special Teams Result\", color=\"Counts\")\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:05.300497Z","iopub.execute_input":"2022-01-03T07:28:05.300729Z","iopub.status.idle":"2022-01-03T07:28:05.359736Z","shell.execute_reply.started":"2022-01-03T07:28:05.300703Z","shell.execute_reply":"2022-01-03T07:28:05.358737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. \"Kickoff Team Recovery\", \"Blocked Punt\", \"Blocked Kick Attempt\" have worst results\n2. \"Downed\", \"Out of Bounds\", \"Kick Attempt No Good\" results are not pretty good","metadata":{}},{"cell_type":"code","source":"plays[\"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)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:05.361154Z","iopub.execute_input":"2022-01-03T07:28:05.361381Z","iopub.status.idle":"2022-01-03T07:28:05.391225Z","shell.execute_reply.started":"2022-01-03T07:28:05.361355Z","shell.execute_reply":"2022-01-03T07:28:05.390424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Unique NFL yardline sides and their counts :\")\ng_yard = plays.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":"2022-01-03T07:28:05.392622Z","iopub.execute_input":"2022-01-03T07:28:05.392830Z","iopub.status.idle":"2022-01-03T07:28:05.408490Z","shell.execute_reply.started":"2022-01-03T07:28:05.392806Z","shell.execute_reply":"2022-01-03T07:28:05.407539Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot\npx.bar(g_yard, x=\"Yard Line Side\", y=\"Counts\", title=\"Distinct Count Of NFL Yardline Sides\", color=\"Counts\")","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:05.410185Z","iopub.execute_input":"2022-01-03T07:28:05.410510Z","iopub.status.idle":"2022-01-03T07:28:05.474869Z","shell.execute_reply.started":"2022-01-03T07:28:05.410469Z","shell.execute_reply":"2022-01-03T07:28:05.473941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Unique NFL yardline numbers and their counts :\")\ng_yard = plays.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":"2022-01-03T07:28:05.476096Z","iopub.execute_input":"2022-01-03T07:28:05.476297Z","iopub.status.idle":"2022-01-03T07:28:05.486598Z","shell.execute_reply.started":"2022-01-03T07:28:05.476274Z","shell.execute_reply":"2022-01-03T07:28:05.485769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot\npx.bar(g_yard, x=\"Yard Line Number\", y=\"Counts\", title=\"Distinct Count Of NFL Yard Line Numbers\", color=\"Yard Line Number\")","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:05.487734Z","iopub.execute_input":"2022-01-03T07:28:05.487952Z","iopub.status.idle":"2022-01-03T07:28:05.547051Z","shell.execute_reply.started":"2022-01-03T07:28:05.487925Z","shell.execute_reply":"2022-01-03T07:28:05.546187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plays[\"gameClockhour\"] = pd.to_datetime(plays[\"gameClock\"], format=\"%H:%M:%S\").dt.hour\nprint(plays[\"gameClockhour\"])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:05.548315Z","iopub.execute_input":"2022-01-03T07:28:05.548966Z","iopub.status.idle":"2022-01-03T07:28:05.565710Z","shell.execute_reply.started":"2022-01-03T07:28:05.548929Z","shell.execute_reply":"2022-01-03T07:28:05.564456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Unique NFL game hours and their counts :\")\ng_hour = plays.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":"2022-01-03T07:28:05.567147Z","iopub.execute_input":"2022-01-03T07:28:05.567409Z","iopub.status.idle":"2022-01-03T07:28:05.578074Z","shell.execute_reply.started":"2022-01-03T07:28:05.567361Z","shell.execute_reply":"2022-01-03T07:28:05.577157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot\npx.bar(g_hour, x=\"Game Hour\", y=\"Counts\", title=\"Distinct Count Of NFL Game Hours\", color=\"Counts\")\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:05.579631Z","iopub.execute_input":"2022-01-03T07:28:05.579954Z","iopub.status.idle":"2022-01-03T07:28:05.637737Z","shell.execute_reply.started":"2022-01-03T07:28:05.579926Z","shell.execute_reply":"2022-01-03T07:28:05.636897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Unique NFL penalty codes and their counts :\")\ng_code = plays.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":"2022-01-03T07:28:05.638836Z","iopub.execute_input":"2022-01-03T07:28:05.639044Z","iopub.status.idle":"2022-01-03T07:28:05.653981Z","shell.execute_reply.started":"2022-01-03T07:28:05.639018Z","shell.execute_reply":"2022-01-03T07:28:05.652847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot\npx.bar(g_code, x=\"Penalty Codes\", y=\"Counts\", title=\"Distinct Count Of NFL Penalty Codes\", color=\"Counts\")","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:05.655262Z","iopub.execute_input":"2022-01-03T07:28:05.655715Z","iopub.status.idle":"2022-01-03T07:28:05.714618Z","shell.execute_reply.started":"2022-01-03T07:28:05.655680Z","shell.execute_reply":"2022-01-03T07:28:05.713736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Unique NFL penalty yards and their counts :\")\ngp_yard = plays.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":"2022-01-03T07:28:05.715971Z","iopub.execute_input":"2022-01-03T07:28:05.716837Z","iopub.status.idle":"2022-01-03T07:28:05.730805Z","shell.execute_reply.started":"2022-01-03T07:28:05.716788Z","shell.execute_reply":"2022-01-03T07:28:05.730038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Histogram plot\npx.histogram(plays, x=\"penaltyYards\", nbins=15 , title=\"Distinct Count Of NFL Visitor Teams\", color_discrete_sequence=[\"royalblue\"])\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:05.732160Z","iopub.execute_input":"2022-01-03T07:28:05.732651Z","iopub.status.idle":"2022-01-03T07:28:05.836255Z","shell.execute_reply.started":"2022-01-03T07:28:05.732610Z","shell.execute_reply":"2022-01-03T07:28:05.835471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Unique NFL pre-snap home scores and their counts :\")\ng_home = plays.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":"2022-01-03T07:28:05.837672Z","iopub.execute_input":"2022-01-03T07:28:05.837954Z","iopub.status.idle":"2022-01-03T07:28:05.851645Z","shell.execute_reply.started":"2022-01-03T07:28:05.837917Z","shell.execute_reply":"2022-01-03T07:28:05.850645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Histogram plot\npx.histogram(plays, x=\"preSnapHomeScore\", nbins=25, title=\"Distinct Count Of NFL Pre-Snap Home Scores\", color_discrete_sequence=[\"red\"])\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:05.853060Z","iopub.execute_input":"2022-01-03T07:28:05.853450Z","iopub.status.idle":"2022-01-03T07:28:05.955069Z","shell.execute_reply.started":"2022-01-03T07:28:05.853409Z","shell.execute_reply":"2022-01-03T07:28:05.954198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Unique NFL pre-snap visitor scores and their counts :\")\ng_visitor = plays.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":"2022-01-03T07:28:05.956474Z","iopub.execute_input":"2022-01-03T07:28:05.957017Z","iopub.status.idle":"2022-01-03T07:28:05.968965Z","shell.execute_reply.started":"2022-01-03T07:28:05.956981Z","shell.execute_reply":"2022-01-03T07:28:05.968009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" #Creating Histogram plot\npx.histogram(plays, x=\"preSnapVisitorScore\", nbins=25, title=\"Distinct Count Of NFL Pre-Snap Visitor Scores\", color_discrete_sequence=[\"blueviolet\"])\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:05.970253Z","iopub.execute_input":"2022-01-03T07:28:05.971042Z","iopub.status.idle":"2022-01-03T07:28:06.075401Z","shell.execute_reply.started":"2022-01-03T07:28:05.970997Z","shell.execute_reply":"2022-01-03T07:28:06.074479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Unique NFL pass results and their counts :\")\ng_res = plays.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":"2022-01-03T07:28:06.076843Z","iopub.execute_input":"2022-01-03T07:28:06.077169Z","iopub.status.idle":"2022-01-03T07:28:06.093321Z","shell.execute_reply.started":"2022-01-03T07:28:06.077127Z","shell.execute_reply":"2022-01-03T07:28:06.092237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot\npx.bar(g_res, x=\"Pass Results\", y=\"Counts\", title=\"Distinct Count Of NFL Pass Results\", color=\"Counts\")\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:06.094622Z","iopub.execute_input":"2022-01-03T07:28:06.095032Z","iopub.status.idle":"2022-01-03T07:28:06.325268Z","shell.execute_reply.started":"2022-01-03T07:28:06.094940Z","shell.execute_reply":"2022-01-03T07:28:06.324521Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Unique NFL kick lengths and their counts :\")\ng_kick = plays.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":"2022-01-03T07:28:06.326752Z","iopub.execute_input":"2022-01-03T07:28:06.327087Z","iopub.status.idle":"2022-01-03T07:28:06.342011Z","shell.execute_reply.started":"2022-01-03T07:28:06.327044Z","shell.execute_reply":"2022-01-03T07:28:06.340845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot\npx.bar(g_kick, x=\"Kick Length\", y=\"Counts\", title=\"Distinct Count Of NFL Kick lengths\", color=\"Kick Length\")\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:06.343514Z","iopub.execute_input":"2022-01-03T07:28:06.344187Z","iopub.status.idle":"2022-01-03T07:28:06.408259Z","shell.execute_reply.started":"2022-01-03T07:28:06.344139Z","shell.execute_reply":"2022-01-03T07:28:06.407674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Unique NFL kick return yardages and their counts :\")\ng_yard = plays.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":"2022-01-03T07:28:06.409330Z","iopub.execute_input":"2022-01-03T07:28:06.410004Z","iopub.status.idle":"2022-01-03T07:28:06.423868Z","shell.execute_reply.started":"2022-01-03T07:28:06.409973Z","shell.execute_reply":"2022-01-03T07:28:06.422612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Histogram plot\npx.histogram(plays, x=\"kickReturnYardage\", nbins=25 , title=\"Distinct Count Of NFL Kick Return Yardages\",  color_discrete_sequence=[\"mediumvioletred\"])\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:06.425137Z","iopub.execute_input":"2022-01-03T07:28:06.426210Z","iopub.status.idle":"2022-01-03T07:28:06.535961Z","shell.execute_reply.started":"2022-01-03T07:28:06.426132Z","shell.execute_reply":"2022-01-03T07:28:06.535068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Unique NFL play results and their counts :\")\ngp_res = plays.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":"2022-01-03T07:28:06.537563Z","iopub.execute_input":"2022-01-03T07:28:06.538112Z","iopub.status.idle":"2022-01-03T07:28:06.554238Z","shell.execute_reply.started":"2022-01-03T07:28:06.538015Z","shell.execute_reply":"2022-01-03T07:28:06.552834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Histogram plot\npx.histogram(plays, x=\"playResult\", nbins=10, title=\"Distinct Count Of NFL Play Results\", color_discrete_sequence=[\"blue\"])\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:06.556108Z","iopub.execute_input":"2022-01-03T07:28:06.556589Z","iopub.status.idle":"2022-01-03T07:28:06.668240Z","shell.execute_reply.started":"2022-01-03T07:28:06.556531Z","shell.execute_reply":"2022-01-03T07:28:06.666221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Unique NFL absolute yardline numbers and their counts :\")\ng_abyl = plays.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":"2022-01-03T07:28:06.670118Z","iopub.execute_input":"2022-01-03T07:28:06.670933Z","iopub.status.idle":"2022-01-03T07:28:06.684689Z","shell.execute_reply.started":"2022-01-03T07:28:06.670895Z","shell.execute_reply":"2022-01-03T07:28:06.683982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating Bar plot\npx.bar(g_abyl, x=\"Absolute YardLine Number\", y=\"Counts\", title=\"Distinct Count Of NFL Absolute Yard Line Number\", color=\"Absolute YardLine Number\")\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:06.685766Z","iopub.execute_input":"2022-01-03T07:28:06.686751Z","iopub.status.idle":"2022-01-03T07:28:06.749855Z","shell.execute_reply.started":"2022-01-03T07:28:06.686691Z","shell.execute_reply":"2022-01-03T07:28:06.749229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Tracking2018 Data","metadata":{}},{"cell_type":"code","source":"# loading the tracking2018 dataset\ntracking_2018 = pd.read_csv(\"../input/nfl-big-data-bowl-2022/tracking2018.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:06.751014Z","iopub.execute_input":"2022-01-03T07:28:06.751427Z","iopub.status.idle":"2022-01-03T07:28:45.974336Z","shell.execute_reply.started":"2022-01-03T07:28:06.751378Z","shell.execute_reply":"2022-01-03T07:28:45.973479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking its shape\ntracking_2018.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:45.975712Z","iopub.execute_input":"2022-01-03T07:28:45.976017Z","iopub.status.idle":"2022-01-03T07:28:45.982052Z","shell.execute_reply.started":"2022-01-03T07:28:45.975978Z","shell.execute_reply":"2022-01-03T07:28:45.981255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#cheking 1st 5 rows\ntracking_2018.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:45.983165Z","iopub.execute_input":"2022-01-03T07:28:45.983483Z","iopub.status.idle":"2022-01-03T07:28:46.010127Z","shell.execute_reply.started":"2022-01-03T07:28:45.983452Z","shell.execute_reply":"2022-01-03T07:28:46.009258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Fetching the information of each column of tracking_2018 data frame\ntracking_2018.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:46.011423Z","iopub.execute_input":"2022-01-03T07:28:46.011856Z","iopub.status.idle":"2022-01-03T07:28:46.024046Z","shell.execute_reply.started":"2022-01-03T07:28:46.011813Z","shell.execute_reply":"2022-01-03T07:28:46.023370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. Dtype of 'time' column is object","metadata":{}},{"cell_type":"code","source":"# Counting the Null Values\ntracking_2018.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:46.025025Z","iopub.execute_input":"2022-01-03T07:28:46.025529Z","iopub.status.idle":"2022-01-03T07:28:49.781132Z","shell.execute_reply.started":"2022-01-03T07:28:46.025488Z","shell.execute_reply":"2022-01-03T07:28:49.780265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. so many null values are present in 'o', 'dir', 'nflId', 'jerseyNumber' and 'position' column","metadata":{}},{"cell_type":"code","source":"# splitting date from datetime\ntracking_2018['date'] = pd.DatetimeIndex(tracking_2018['time']).date\nprint(tracking_2018[\"date\"])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:49.782321Z","iopub.execute_input":"2022-01-03T07:28:49.782664Z","iopub.status.idle":"2022-01-03T07:28:55.817255Z","shell.execute_reply.started":"2022-01-03T07:28:49.782629Z","shell.execute_reply":"2022-01-03T07:28:55.816441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Listing out unique values from date column\nprint(\"Unique NFL dates and their counts :\")\ntr18_date = tracking_2018.pivot_table(index = ['date'], aggfunc = 'size') \ntr18_date = tr18_date.reset_index()\ntr18_date.columns= [\"Date\", \"Counts\"]\ntr18_date = tr18_date.sort_values(\"Counts\", ascending = False)\nprint(tr18_date)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:55.818357Z","iopub.execute_input":"2022-01-03T07:28:55.818578Z","iopub.status.idle":"2022-01-03T07:28:57.106383Z","shell.execute_reply.started":"2022-01-03T07:28:55.818552Z","shell.execute_reply":"2022-01-03T07:28:57.105581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Visualizing NFL dates by Bar plot\npx.bar(tr18_date, x=\"Date\", y=\"Counts\", title=\"Distinct Count Of NFL Dates\", color=\"Counts\")","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:57.107515Z","iopub.execute_input":"2022-01-03T07:28:57.107736Z","iopub.status.idle":"2022-01-03T07:28:57.169854Z","shell.execute_reply.started":"2022-01-03T07:28:57.107710Z","shell.execute_reply":"2022-01-03T07:28:57.168891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. SUNDAY is a favorable day for conducting of event.\n2. Most games played on 30th Dec 2018.","metadata":{}},{"cell_type":"code","source":"# Creating a table of coordinates of players position of home team opponents team and foot ball through out the play of playId == 36 and gameId == 2018123000\ndata_18= tracking_2018.query('playId == 36 and gameId == 2018123000')\nprint(data_18[[\"x\", \"y\", \"team\"]])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:57.171239Z","iopub.execute_input":"2022-01-03T07:28:57.171640Z","iopub.status.idle":"2022-01-03T07:28:59.847284Z","shell.execute_reply.started":"2022-01-03T07:28:57.171596Z","shell.execute_reply":"2022-01-03T07:28:59.846657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# players location throughout the game\npx.scatter(data_18, x=\"x\", y=\"y\", color=\"team\",width=1000,height=800)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:59.850299Z","iopub.execute_input":"2022-01-03T07:28:59.850782Z","iopub.status.idle":"2022-01-03T07:28:59.924926Z","shell.execute_reply.started":"2022-01-03T07:28:59.850707Z","shell.execute_reply":"2022-01-03T07:28:59.924088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating a table of coordinates of players position of home team opponents team and foot ball through out the play of playId == 36 and gameId == 2018102107\ndata_18 = tracking_2018.query('playId == 36 and gameId == 2018102107')\nprint(data_18[[\"x\", \"y\", \"team\"]])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:28:59.926217Z","iopub.execute_input":"2022-01-03T07:28:59.926451Z","iopub.status.idle":"2022-01-03T07:29:00.002748Z","shell.execute_reply.started":"2022-01-03T07:28:59.926424Z","shell.execute_reply":"2022-01-03T07:29:00.001875Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# players location throughout the game\npx.scatter(data_18, x=\"x\", y=\"y\", color=\"team\",width=1000,height=800)\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:29:00.004131Z","iopub.execute_input":"2022-01-03T07:29:00.004433Z","iopub.status.idle":"2022-01-03T07:29:00.076639Z","shell.execute_reply.started":"2022-01-03T07:29:00.004377Z","shell.execute_reply":"2022-01-03T07:29:00.075775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating a table of coordinates of players position of home team opponents team and foot ball through out the play of position == \"CB\" and gameId == 2018111900\ndata_18 = tracking_2018.query('position == \"CB\" and gameId == 2018111900')\nprint(data_18[[\"x\", \"y\", \"team\"]])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:29:00.077742Z","iopub.execute_input":"2022-01-03T07:29:00.077958Z","iopub.status.idle":"2022-01-03T07:29:00.406096Z","shell.execute_reply.started":"2022-01-03T07:29:00.077931Z","shell.execute_reply":"2022-01-03T07:29:00.405151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# players location throughout the game\npx.scatter(data_18, x=\"x\", y=\"y\", color=\"team\",width=1000,height=800)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:29:00.407427Z","iopub.execute_input":"2022-01-03T07:29:00.407828Z","iopub.status.idle":"2022-01-03T07:29:00.488072Z","shell.execute_reply.started":"2022-01-03T07:29:00.407788Z","shell.execute_reply":"2022-01-03T07:29:00.487077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating a table of coordinates of players position of home team opponents team and foot ball through out the play of position == \"RB\" and gameId == 2018093009\ndata_18 = tracking_2018.query('position == \"RB\" and gameId == 2018093009')\nprint(data_18[[\"x\", \"y\", \"team\"]])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:29:00.489495Z","iopub.execute_input":"2022-01-03T07:29:00.489786Z","iopub.status.idle":"2022-01-03T07:29:00.817438Z","shell.execute_reply.started":"2022-01-03T07:29:00.489747Z","shell.execute_reply":"2022-01-03T07:29:00.816794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# players location throughout the game\npx.scatter(data_18, x=\"x\", y=\"y\", color=\"team\",width=1000,height=800)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:29:00.818321Z","iopub.execute_input":"2022-01-03T07:29:00.818863Z","iopub.status.idle":"2022-01-03T07:29:00.882102Z","shell.execute_reply.started":"2022-01-03T07:29:00.818828Z","shell.execute_reply":"2022-01-03T07:29:00.881287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating a table of coordinates of players position of home team opponents team and foot ball through out the play of position == \"LB\" and gameId == 2018111900\ndata_18 = tracking_2018.query('position == \"LB\" and gameId == 2018111900')\nprint(data_18[[\"x\", \"y\", \"team\"]])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:29:00.883429Z","iopub.execute_input":"2022-01-03T07:29:00.883895Z","iopub.status.idle":"2022-01-03T07:29:01.142893Z","shell.execute_reply.started":"2022-01-03T07:29:00.883862Z","shell.execute_reply":"2022-01-03T07:29:01.141927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# players location throughout the game\npx.scatter(data_18, x=\"x\", y=\"y\", color=\"team\",width=1000,height=800)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:29:01.144148Z","iopub.execute_input":"2022-01-03T07:29:01.144511Z","iopub.status.idle":"2022-01-03T07:29:01.222975Z","shell.execute_reply.started":"2022-01-03T07:29:01.144478Z","shell.execute_reply":"2022-01-03T07:29:01.222407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tracking_2018['date'] = pd.DatetimeIndex(tracking_2018['date'])\nrslt_df = tracking_2018[tracking_2018['date'] == '2018-10-09']\nprint(rslt_df.head())","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:29:01.223908Z","iopub.execute_input":"2022-01-03T07:29:01.224515Z","iopub.status.idle":"2022-01-03T07:29:03.662293Z","shell.execute_reply.started":"2022-01-03T07:29:01.224482Z","shell.execute_reply":"2022-01-03T07:29:03.661260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Animation of a game done using coordinates and time \n# this animation shows the game played in 2018-10-09\nfig = px.scatter(rslt_df, x=\"x\", y=\"y\", animation_frame=\"time\", color=\"team\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:29:03.663523Z","iopub.execute_input":"2022-01-03T07:29:03.663763Z","iopub.status.idle":"2022-01-03T07:29:16.001032Z","shell.execute_reply.started":"2022-01-03T07:29:03.663735Z","shell.execute_reply":"2022-01-03T07:29:15.999989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rslt_df = tracking_2018[tracking_2018['date'] == '2018-11-30']\nprint(rslt_df.head())","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:29:16.003189Z","iopub.execute_input":"2022-01-03T07:29:16.004262Z","iopub.status.idle":"2022-01-03T07:29:16.085468Z","shell.execute_reply.started":"2022-01-03T07:29:16.004215Z","shell.execute_reply":"2022-01-03T07:29:16.084506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#this animation shows the game played in 2018-11-30\nfig = px.scatter(rslt_df, x=\"x\", y=\"y\", animation_frame=\"time\", color=\"team\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:29:16.087483Z","iopub.execute_input":"2022-01-03T07:29:16.088235Z","iopub.status.idle":"2022-01-03T07:29:29.713029Z","shell.execute_reply.started":"2022-01-03T07:29:16.088188Z","shell.execute_reply":"2022-01-03T07:29:29.712070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Tracking2019 Data","metadata":{}},{"cell_type":"code","source":"#loading the dataset\ntracking_2019 = pd.read_csv(\"../input/nfl-big-data-bowl-2022/tracking2019.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:29:29.716126Z","iopub.execute_input":"2022-01-03T07:29:29.716803Z","iopub.status.idle":"2022-01-03T07:30:05.887683Z","shell.execute_reply.started":"2022-01-03T07:29:29.716752Z","shell.execute_reply":"2022-01-03T07:30:05.886495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking shape of the dataset\ntracking_2019.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:30:05.889595Z","iopub.execute_input":"2022-01-03T07:30:05.890417Z","iopub.status.idle":"2022-01-03T07:30:05.897906Z","shell.execute_reply.started":"2022-01-03T07:30:05.890339Z","shell.execute_reply":"2022-01-03T07:30:05.896641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking summary of the dataset\ntracking_2019.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:30:05.899676Z","iopub.execute_input":"2022-01-03T07:30:05.900342Z","iopub.status.idle":"2022-01-03T07:30:05.923091Z","shell.execute_reply.started":"2022-01-03T07:30:05.900293Z","shell.execute_reply":"2022-01-03T07:30:05.921890Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. Dtype of 'time' column is object","metadata":{}},{"cell_type":"code","source":"tracking_2019['date'] = pd.DatetimeIndex(tracking_2019['time']).date\nprint(tracking_2019[\"date\"])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:30:05.924311Z","iopub.execute_input":"2022-01-03T07:30:05.925491Z","iopub.status.idle":"2022-01-03T07:30:11.734724Z","shell.execute_reply.started":"2022-01-03T07:30:05.925444Z","shell.execute_reply":"2022-01-03T07:30:11.733745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Unique NFL dates and their counts :\")\ntr19_date = tracking_2019.pivot_table(index = ['date'], aggfunc = 'size') \ntr19_date = tr19_date.reset_index()\ntr19_date.columns= [\"Date\", \"Counts\"]\ntr19_date = tr19_date.sort_values(\"Counts\", ascending = False)\nprint(tr19_date)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:30:11.736469Z","iopub.execute_input":"2022-01-03T07:30:11.736792Z","iopub.status.idle":"2022-01-03T07:30:12.996280Z","shell.execute_reply.started":"2022-01-03T07:30:11.736737Z","shell.execute_reply":"2022-01-03T07:30:12.995325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"px.bar(tr19_date, x=\"Date\", y=\"Counts\", title=\"Distinct Count Of NFL Dates\", color=\"Counts\")","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:30:12.997447Z","iopub.execute_input":"2022-01-03T07:30:12.998257Z","iopub.status.idle":"2022-01-03T07:30:13.066504Z","shell.execute_reply.started":"2022-01-03T07:30:12.998221Z","shell.execute_reply":"2022-01-03T07:30:13.065497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n- *SUNDAY* is a favorable day for conducting of event.\n- Most games played on *29th dec 2019*.","metadata":{}},{"cell_type":"code","source":"#checking for null value\ntracking_2019.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:30:13.068153Z","iopub.execute_input":"2022-01-03T07:30:13.068423Z","iopub.status.idle":"2022-01-03T07:30:17.187846Z","shell.execute_reply.started":"2022-01-03T07:30:13.068379Z","shell.execute_reply":"2022-01-03T07:30:17.186991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. so many null values are present in 'o', 'dir', 'nflId', 'jerseyNumber' and 'position' column","metadata":{}},{"cell_type":"code","source":"#Creating a table of coordinates of players position of home team opponents team and foot ball through out the play of playId == 36 and gameId == 2019122900\ndata_19 = tracking_2019.query('playId == 36 and gameId == 2019122900')\nprint(data_19[[\"x\", \"y\", \"team\"]])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:30:17.189238Z","iopub.execute_input":"2022-01-03T07:30:17.189701Z","iopub.status.idle":"2022-01-03T07:30:19.872472Z","shell.execute_reply.started":"2022-01-03T07:30:17.189660Z","shell.execute_reply":"2022-01-03T07:30:19.871547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" px.scatter(data_19, x=\"x\", y=\"y\", color=\"team\",width=1000,height=800)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:30:19.873924Z","iopub.execute_input":"2022-01-03T07:30:19.874170Z","iopub.status.idle":"2022-01-03T07:30:19.947927Z","shell.execute_reply.started":"2022-01-03T07:30:19.874141Z","shell.execute_reply":"2022-01-03T07:30:19.947161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Creating a table of coordinates of players position of home team opponents team and foot ball through out the play of playId == 3554 and gameId == 2019090901\ndata_19 = tracking_2019.query('playId == 3554 and gameId == 2019090901')\nprint(data_19[[\"x\", \"y\", \"team\"]])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:30:19.949171Z","iopub.execute_input":"2022-01-03T07:30:19.949374Z","iopub.status.idle":"2022-01-03T07:30:20.025419Z","shell.execute_reply.started":"2022-01-03T07:30:19.949350Z","shell.execute_reply":"2022-01-03T07:30:20.024627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.scatter(data_19, x=\"x\", y=\"y\", color=\"team\",width=1000,height=800)\nfig.show()\n#  players location throughout the game","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:30:20.026738Z","iopub.execute_input":"2022-01-03T07:30:20.026962Z","iopub.status.idle":"2022-01-03T07:30:20.092864Z","shell.execute_reply.started":"2022-01-03T07:30:20.026935Z","shell.execute_reply":"2022-01-03T07:30:20.092062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tracking_2019['date'] = pd.DatetimeIndex(tracking_2019['date'])\nrslt_df = tracking_2019[tracking_2019['date'] == '2019-09-10']\nprint(rslt_df.head())","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:30:20.094346Z","iopub.execute_input":"2022-01-03T07:30:20.094800Z","iopub.status.idle":"2022-01-03T07:30:22.360374Z","shell.execute_reply.started":"2022-01-03T07:30:20.094766Z","shell.execute_reply":"2022-01-03T07:30:22.359564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#This animation shows the game played in 2019-09-10\nfig = px.scatter(rslt_df, x=\"x\", y=\"y\", animation_frame=\"time\", color=\"team\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:30:22.361617Z","iopub.execute_input":"2022-01-03T07:30:22.361832Z","iopub.status.idle":"2022-01-03T07:30:51.207050Z","shell.execute_reply.started":"2022-01-03T07:30:22.361806Z","shell.execute_reply":"2022-01-03T07:30:51.205628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Tracking2020 Data","metadata":{}},{"cell_type":"code","source":"#loading the dataset\ntracking_2020 = pd.read_csv(\"../input/nfl-big-data-bowl-2022/tracking2020.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:30:51.209930Z","iopub.execute_input":"2022-01-03T07:30:51.210341Z","iopub.status.idle":"2022-01-03T07:31:25.695609Z","shell.execute_reply.started":"2022-01-03T07:30:51.210299Z","shell.execute_reply":"2022-01-03T07:31:25.694599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking shape of the dataset\ntracking_2020.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:31:25.697411Z","iopub.execute_input":"2022-01-03T07:31:25.697745Z","iopub.status.idle":"2022-01-03T07:31:25.706363Z","shell.execute_reply.started":"2022-01-03T07:31:25.697706Z","shell.execute_reply":"2022-01-03T07:31:25.705669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking first five rows\ntracking_2020.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:31:25.707586Z","iopub.execute_input":"2022-01-03T07:31:25.707818Z","iopub.status.idle":"2022-01-03T07:31:25.737057Z","shell.execute_reply.started":"2022-01-03T07:31:25.707792Z","shell.execute_reply":"2022-01-03T07:31:25.736049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking the summary of the dataset\ntracking_2020.info()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:31:25.738500Z","iopub.execute_input":"2022-01-03T07:31:25.740242Z","iopub.status.idle":"2022-01-03T07:31:25.758935Z","shell.execute_reply.started":"2022-01-03T07:31:25.740206Z","shell.execute_reply":"2022-01-03T07:31:25.757683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. Dtype of 'time' column is object","metadata":{}},{"cell_type":"code","source":"#creating another column \"date\" and storing date from 'time' column in it\ntracking_2020['date'] = pd.DatetimeIndex(tracking_2020['time']).date","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:31:25.760703Z","iopub.execute_input":"2022-01-03T07:31:25.761177Z","iopub.status.idle":"2022-01-03T07:31:31.312269Z","shell.execute_reply.started":"2022-01-03T07:31:25.761125Z","shell.execute_reply":"2022-01-03T07:31:31.311647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tracking_2020.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:31:31.313562Z","iopub.execute_input":"2022-01-03T07:31:31.313874Z","iopub.status.idle":"2022-01-03T07:31:31.336659Z","shell.execute_reply.started":"2022-01-03T07:31:31.313832Z","shell.execute_reply":"2022-01-03T07:31:31.335666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking for null values\ntracking_2020.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:31:31.338160Z","iopub.execute_input":"2022-01-03T07:31:31.338382Z","iopub.status.idle":"2022-01-03T07:31:35.347639Z","shell.execute_reply.started":"2022-01-03T07:31:31.338358Z","shell.execute_reply":"2022-01-03T07:31:35.346792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. so many null values are present in 'o', 'dir', 'nflId', 'jerseyNumber' and 'position' column","metadata":{}},{"cell_type":"code","source":"#Listing out unique values from date column\nprint(\"Unique NFL dates and their counts :\")\ntr20_date = tracking_2020.pivot_table(index = ['date'], aggfunc = 'size') \ntr20_date = tr20_date.reset_index()\ntr20_date.columns= [\"Date\", \"Counts\"]\ntr20_date = tr20_date.sort_values(\"Counts\", ascending = False)\nprint(tr20_date)","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:31:35.348808Z","iopub.execute_input":"2022-01-03T07:31:35.349021Z","iopub.status.idle":"2022-01-03T07:31:36.543067Z","shell.execute_reply.started":"2022-01-03T07:31:35.348995Z","shell.execute_reply":"2022-01-03T07:31:36.542179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Visualizing NFL dates by Bar plot\npx.bar(tr20_date, x=\"Date\", y=\"Counts\", title=\"Distinct Count Of NFL Dates\", color=\"Counts\")","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:31:36.544538Z","iopub.execute_input":"2022-01-03T07:31:36.544898Z","iopub.status.idle":"2022-01-03T07:31:36.607658Z","shell.execute_reply.started":"2022-01-03T07:31:36.544857Z","shell.execute_reply":"2022-01-03T07:31:36.606843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*Observation*\n1. SUNDAY is a favorable day for conducting of event.\n2. Most games played on 3rd Jan 2021.","metadata":{}},{"cell_type":"code","source":"# Creating a table of coordinates of players position of home team opponents team and foot ball through out the play \n#of playId = 40 and gameId == 2021010300\ndata_20 = tracking_2020.query('playId == 40 and gameId == 2021010300')\nprint(data_20[[\"x\", \"y\", \"team\"]])","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:31:36.608950Z","iopub.execute_input":"2022-01-03T07:31:36.609433Z","iopub.status.idle":"2022-01-03T07:31:38.970634Z","shell.execute_reply.started":"2022-01-03T07:31:36.609372Z","shell.execute_reply":"2022-01-03T07:31:38.969642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# players location throughout the game\nfig = px.scatter(data_20, x=\"x\", y=\"y\", color=\"team\",width=1000,height=600)\nfig.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:31:38.972118Z","iopub.execute_input":"2022-01-03T07:31:38.972440Z","iopub.status.idle":"2022-01-03T07:31:39.039192Z","shell.execute_reply.started":"2022-01-03T07:31:38.972401Z","shell.execute_reply":"2022-01-03T07:31:39.038175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tracking_2020['date'] = pd.DatetimeIndex(tracking_2020['date'])\nrslt_df20 = tracking_2020[tracking_2020['date'] == '2020-11-27']\nprint(rslt_df20.head())","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:31:39.040702Z","iopub.execute_input":"2022-01-03T07:31:39.040901Z","iopub.status.idle":"2022-01-03T07:31:41.155867Z","shell.execute_reply.started":"2022-01-03T07:31:39.040877Z","shell.execute_reply":"2022-01-03T07:31:41.154984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#This animation shows the game played in 2020-11-27\nfig = px.scatter(rslt_df20, x=\"x\", y=\"y\", animation_frame=\"time\", color=\"team\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-03T07:31:41.157130Z","iopub.execute_input":"2022-01-03T07:31:41.157432Z","iopub.status.idle":"2022-01-03T07:31:46.941877Z","shell.execute_reply.started":"2022-01-03T07:31:41.157375Z","shell.execute_reply":"2022-01-03T07:31:46.940987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}