{"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":"# 🏈 America's  National Football League (NFL)\nBig Data Analysis - The most popular sports league ","metadata":{}},{"cell_type":"markdown","source":"![](https://cdn.iconscout.com/icon/free/png-256/nfl-283167.png)","metadata":{}},{"cell_type":"markdown","source":"# The Challenge 🎯\n\nYour challenge is to generate actionable, practical, and novel insights from player tracking data that corresponds to special teams play. There are several potential topics for participants to analyze. These include, but are not limited to:\n\n1. Create a new special teams metric. The winning algorithm from the 2020 Big Data Bowl has been adopted by the NFL/NFL Network for on air distribution, and we are hopeful that there could be a new stat for special teams plays that could come from this year’s competition\n\n2. Quantify special teams strategy. Special teams’ coaches are among the most creative and innovative in the league. Compare/contrast how each team game plans. Which strategies yield the best results? What are other strategies that could be adopted?\n\n3. Rank special teams players. Each team employs a variety of players (including longsnappers, kickers, punters, and other utility special teams players). How do they stack up with respect to one another?","metadata":{}},{"cell_type":"markdown","source":"Competition Steps:\n\n* Import the required Python libraries\n* Load and explore data (Exploration Data) (EDA)\n* Cleaning Data / Null Values\n* Data analysis, Visualization and histograms","metadata":{}},{"cell_type":"markdown","source":"# Import the required Python libraries 📄","metadata":{}},{"cell_type":"code","source":"import numpy as np \nimport pandas as pd \n\nimport matplotlib.pyplot as plt \nimport matplotlib as mpl\nimport seaborn as sns \nfrom datetime import datetime\nfrom wordcloud import WordCloud, STOPWORDS\n\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:34:59.899093Z","iopub.execute_input":"2021-11-10T14:34:59.899934Z","iopub.status.idle":"2021-11-10T14:34:59.911679Z","shell.execute_reply.started":"2021-11-10T14:34:59.899884Z","shell.execute_reply":"2021-11-10T14:34:59.910982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Loading and Exploration Data (EDA)","metadata":{}},{"cell_type":"markdown","source":"# Games Data 📊","metadata":{}},{"cell_type":"code","source":"# Loading dataset games.csv\ngames_data = pd.read_csv('../input/nfl-big-data-bowl-2022/games.csv')\ngames_data.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:34:59.913800Z","iopub.execute_input":"2021-11-10T14:34:59.914353Z","iopub.status.idle":"2021-11-10T14:34:59.933677Z","shell.execute_reply.started":"2021-11-10T14:34:59.914308Z","shell.execute_reply":"2021-11-10T14:34:59.932857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Get Total (rows, cols) using shape\ngames_data.shape","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:34:59.934944Z","iopub.execute_input":"2021-11-10T14:34:59.935550Z","iopub.status.idle":"2021-11-10T14:34:59.941198Z","shell.execute_reply.started":"2021-11-10T14:34:59.935513Z","shell.execute_reply":"2021-11-10T14:34:59.940437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Cleaning Data / Null Values","metadata":{}},{"cell_type":"code","source":"# Check for Null Values\nnull_values = games_data.isnull().sum()\nnull_values","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:34:59.944007Z","iopub.execute_input":"2021-11-10T14:34:59.944661Z","iopub.status.idle":"2021-11-10T14:34:59.956687Z","shell.execute_reply.started":"2021-11-10T14:34:59.944624Z","shell.execute_reply":"2021-11-10T14:34:59.956101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> No null values","metadata":{}},{"cell_type":"markdown","source":"# Data Analysis, Visualization and Histograms","metadata":{}},{"cell_type":"markdown","source":"* **gameId**\tGame identifier, unique (numeric)\n* **season**\tSeason of game\n* **week**\tWeek of game\n* **gameDate**\tGame Date (time, mm/dd/yyyy)\n* **gameTimeEastern**\tStart time of game (time, HH:MM:SS, EST)\n* **homeTeamAbbr**\tHome team three-letter code (text)\n* **visitorTeamAbbr**\tVisiting team three-letter code (text","metadata":{}},{"cell_type":"code","source":"games_data.info()\n","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:34:59.957731Z","iopub.execute_input":"2021-11-10T14:34:59.958237Z","iopub.status.idle":"2021-11-10T14:34:59.972237Z","shell.execute_reply.started":"2021-11-10T14:34:59.958200Z","shell.execute_reply":"2021-11-10T14:34:59.971329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Group By Season**","metadata":{}},{"cell_type":"code","source":"games_data.groupby('season').size()","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:34:59.973414Z","iopub.execute_input":"2021-11-10T14:34:59.973956Z","iopub.status.idle":"2021-11-10T14:34:59.988075Z","shell.execute_reply.started":"2021-11-10T14:34:59.973920Z","shell.execute_reply":"2021-11-10T14:34:59.987235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<iframe src=\"https://www.kaggle.com/embed/girishkumarsahu/nfl-big-data-bowl-2022?cellIds=10&kernelSessionId=79075208\" height=\"300\" style=\"margin: 0 auto; width: 100%; max-width: 950px;\" frameborder=\"0\" scrolling=\"auto\" title=\"NFL_Big_Data_Bowl_2022\"></iframe>\n","metadata":{}},{"cell_type":"code","source":"# convert integers to date \ngames_data[\"gameDate\"] = pd.to_datetime(games_data[\"gameDate\"])\n# extract month\ngames_data['Year'] = games_data[\"gameDate\"].dt.month_name()\n# extract days\ngames_data['Week'] = games_data[\"gameDate\"].dt.day_name()\n\nsns.set_style(\"whitegrid\")\nplt.figure(figsize=(8, 6))\nax = plt.gca()\n\nsns.countplot(x='season', data=games_data, hue='Year', lw=2, ax=ax).set(title='Games in Year, Season')\nax.legend(loc='center right', bbox_to_anchor=(1.5, 0.5), ncol=1)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:35:00.010256Z","iopub.execute_input":"2021-11-10T14:35:00.010520Z","iopub.status.idle":"2021-11-10T14:35:00.307795Z","shell.execute_reply.started":"2021-11-10T14:35:00.010492Z","shell.execute_reply":"2021-11-10T14:35:00.306967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Plays Data 📊","metadata":{}},{"cell_type":"code","source":"plays_data = pd.read_csv(\"../input/nfl-big-data-bowl-2022/plays.csv\")\nplays_data.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:35:00.309486Z","iopub.execute_input":"2021-11-10T14:35:00.309718Z","iopub.status.idle":"2021-11-10T14:35:00.420926Z","shell.execute_reply.started":"2021-11-10T14:35:00.309688Z","shell.execute_reply":"2021-11-10T14:35:00.420138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plays_data.shape","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:35:00.422278Z","iopub.execute_input":"2021-11-10T14:35:00.423091Z","iopub.status.idle":"2021-11-10T14:35:00.429645Z","shell.execute_reply.started":"2021-11-10T14:35:00.423044Z","shell.execute_reply":"2021-11-10T14:35:00.428898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Players Data 📊","metadata":{}},{"cell_type":"code","source":"players_data = pd.read_csv(\"../input/nfl-big-data-bowl-2022/players.csv\")\nplayers_data","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:35:00.431457Z","iopub.execute_input":"2021-11-10T14:35:00.431833Z","iopub.status.idle":"2021-11-10T14:35:00.464712Z","shell.execute_reply.started":"2021-11-10T14:35:00.431800Z","shell.execute_reply":"2021-11-10T14:35:00.463723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Texas Tech**","metadata":{}},{"cell_type":"code","source":"players_data.query('collegeName == \"Texas Tech\"')","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:35:00.465741Z","iopub.execute_input":"2021-11-10T14:35:00.466428Z","iopub.status.idle":"2021-11-10T14:35:00.485607Z","shell.execute_reply.started":"2021-11-10T14:35:00.466378Z","shell.execute_reply":"2021-11-10T14:35:00.484831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"collegs_data = players_data.groupby('collegeName').size()","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:35:00.487007Z","iopub.execute_input":"2021-11-10T14:35:00.487731Z","iopub.status.idle":"2021-11-10T14:35:00.498566Z","shell.execute_reply.started":"2021-11-10T14:35:00.487682Z","shell.execute_reply":"2021-11-10T14:35:00.497692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mpl.rcParams['font.size']=12                 \nmpl.rcParams['savefig.dpi']=100             \nmpl.rcParams['figure.subplot.bottom']=.1 \n\nstopwords = set(STOPWORDS)\n\nwordcloud = WordCloud(\n                          background_color='white',\n                          stopwords=stopwords,\n                          max_words=400,\n                          max_font_size=40, \n                          random_state=42\n                         ).generate(str(players_data['collegeName']))\n\nprint(wordcloud)\nfig = plt.figure(1)\nplt.imshow(wordcloud)\nplt.axis('off')\nplt.show()\nfig.savefig(\"word1.png\", dpi=900)","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:35:00.499788Z","iopub.execute_input":"2021-11-10T14:35:00.500333Z","iopub.status.idle":"2021-11-10T14:35:02.172094Z","shell.execute_reply.started":"2021-11-10T14:35:00.500287Z","shell.execute_reply":"2021-11-10T14:35:02.171114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Players names words cloud**","metadata":{}},{"cell_type":"code","source":"mpl.rcParams['font.size']=12                 \nmpl.rcParams['savefig.dpi']=100             \nmpl.rcParams['figure.subplot.bottom']=.1 \n\nstopwords = set(STOPWORDS)\n\nwordcloud = WordCloud(\n                          background_color='white',\n                          stopwords=stopwords,\n                          max_words=200,\n                          max_font_size=30, \n                          random_state=42\n                         ).generate(str(players_data['displayName']))\n\nprint(wordcloud)\nfig = plt.figure(1)\nplt.imshow(wordcloud)\nplt.axis('off')\nplt.show()\nfig.savefig(\"word1.png\", dpi=900)","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:35:02.173760Z","iopub.execute_input":"2021-11-10T14:35:02.174053Z","iopub.status.idle":"2021-11-10T14:35:04.031094Z","shell.execute_reply.started":"2021-11-10T14:35:02.174014Z","shell.execute_reply":"2021-11-10T14:35:04.030226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"collegs_data.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:35:04.032398Z","iopub.execute_input":"2021-11-10T14:35:04.032636Z","iopub.status.idle":"2021-11-10T14:35:04.039784Z","shell.execute_reply.started":"2021-11-10T14:35:04.032605Z","shell.execute_reply":"2021-11-10T14:35:04.038947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"collegs_data.tail()","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:35:04.042077Z","iopub.execute_input":"2021-11-10T14:35:04.042422Z","iopub.status.idle":"2021-11-10T14:35:04.053510Z","shell.execute_reply.started":"2021-11-10T14:35:04.042381Z","shell.execute_reply":"2021-11-10T14:35:04.052575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Number of Collegs partecipating NFL**","metadata":{}},{"cell_type":"code","source":"# America's  National Football League\nprint('Number of Collegs', collegs_data.shape)","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:35:04.054380Z","iopub.execute_input":"2021-11-10T14:35:04.054961Z","iopub.status.idle":"2021-11-10T14:35:04.064984Z","shell.execute_reply.started":"2021-11-10T14:35:04.054931Z","shell.execute_reply":"2021-11-10T14:35:04.064044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Count of Players by Position**","metadata":{}},{"cell_type":"code","source":"players_data['Position'].value_counts() \\\n    .sort_values(ascending=True) \\\n    .plot(kind='barh', figsize=(10, 15                               ),\n         title='Count of Players by Position')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-10T14:35:04.066480Z","iopub.execute_input":"2021-11-10T14:35:04.066875Z","iopub.status.idle":"2021-11-10T14:35:04.476588Z","shell.execute_reply.started":"2021-11-10T14:35:04.066845Z","shell.execute_reply":"2021-11-10T14:35:04.475755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<iframe src=\"https://www.kaggle.com/embed/girishkumarsahu/nfl-big-data-bowl-2022?cellIds=10&kernelSessionId=79075208\" height=\"300\" style=\"margin: 0 auto; width: 100%; max-width: 950px;\" frameborder=\"0\" scrolling=\"auto\" title=\"NFL_Big_Data_Bowl_2022\"></iframe>","metadata":{}},{"cell_type":"markdown","source":"Please consider voting if you find it useful 👍\n\n**Thanks**","metadata":{}}]}