{"cells":[{"metadata":{"_uuid":"8dc924a4364b785532ca1e5d066570dfcbe0a428"},"cell_type":"markdown","source":"# Glossary\n\n- <a href='#intro'><b>1 Introduction</b></a>\n- <a href='#importing'><b>2 Importing and installing dependencies</b></a>\n- <a href='#game_data'><b>3 Game Data</b></a>\n    - <a href='#null'><b>3.1 Checking for Null values</b></a>\n        - <a href='#null_needs'>3.1.1 Checking whether or not we need the columns with missing values</a>\n        - <a href='#null_drop'>3.1.2 Dropping unnecessary columns</a>\n    - <a href='#types'><b>3.2 Checking column types</b></a>\n        - <a href='#memory_usage'> 3.2.1 Changing column types for less memory usage</a>\n    - <a href='#scatter_plot'><b>3.3 Plotting the games of the season</b></a>\n- <a href='#video_footage_injury'><b>4 Video Footage Injury</b></a>\n    - <a href='#video_footage_injury_null'><b>4.1 Checking for Null values</b></a>\n    - <a href='#video_footage_injury_types'><b>4.2 Checking column types</b></a>\n    - <a href='#video_footage_injury_season'><b>4.3 Plotting concussions by season and year</b></a>\n        - <a href='#video_footage_injury_season_season'>4.3.1 Concussions by season and year</a>\n        - <a href='#video_footage_injury_season_week'>4.3.2 Concussions by week and quarter</a>\n- <a href='#video_review'><b>5 Video Review</b></a>\n    - <a href='#video_review_null'><b>5.1 Checking for Null values</b></a>\n        - <a href='#video_review_null_needs'>5.1.1 Checking whether or not we need the columns with missing values</a>\n    - <a href='#video_review_types'><b>5.2 Checking column types</b></a>\n        - <a href='#video_review_usage'> 5.2.1 Changing column types for less memory usage</a>\n    - <a href='#video_review_plot'><b>5.3 Plotting concussions by category</b></a>\n- <a href='#video_footage_control'><b>6 Video Footage Control</b></a>\n    - <a href='#video_footage_control_null'><b>6.1 Checking for Null values</b></a>\n    - <a href='#video_footage_control_types'><b>6.2 Checking column types</b></a>\n    - <a href='#video_footage_control_types_plot'><b>6.3 Plotting video reviews by quarter</b></a>\n- <a href='#play_information'><b>7 Play Information</b></a>\n    - <a href='#play_information_null'><b>7.1 Checking for Null values</b></a>\n    - <a href='#play_information_types'><b>7.2 Checking column types</b></a>\n    - <a href='#play_information_types_plot'><b>7.3 Plotting total amount of plays per week</b></a>\n- <a href='#play_player_role_data'><b>8 Play Player Role Data</b></a>\n    - <a href='#play_player_role_data_null'><b>8.1 Checking for Null values</b></a>\n    - <a href='#play_player_role_data_types'><b>8.2 Checking column types</b></a>\n    - <a href='#play_player_role_data_plot'><b>8.3 Plotting amount of players per role</b></a>\n- <a href='#player_punt_data'><b>9 Player Punt Data</b></a>\n    - <a href='#player_punt_data_null'><b>9.1 Checking for Null values</b></a>\n    - <a href='#player_punt_data_types'><b>9.2 Checking column types</b></a>\n    - <a href='#player_punt_data_plot'><b>9.3 Plotting amount of players per role</b></a>\n- <a href='#player_data'><b>10 Player Data</b></a>\n    - <a href='#player_data_plotting_injuries'><b>10.1 Plotting injuries from punts</b></a>\n    - <a href='#player_data_plotting_aggressive_teams'><b>10.2 Plotting most aggressive teams</b></a>\n    - <a href='#player_data_plotting_locations'><b>10.3 Plotting location of injuries in the field</b></a>\n    - <a href='#player_data_plotting_time'><b>10.4 Plotting time of injuries</b></a>\n- <a href='#play_data'><b>11 Play Data</b></a>"},{"metadata":{"_uuid":"2bd94780a923fd9ab4127784d3ebf1d96b743f7c"},"cell_type":"markdown","source":"# <a id='intro'><b>1 Introduction:</b></a>"},{"metadata":{"_uuid":"864d5ec9b0fa231db82bde367bef744aebd71762"},"cell_type":"markdown","source":"The National Football League is America's most popular sports league, comprised of 32 franchises that compete each year to win the Super Bowl, the world's biggest annual sporting event. Founded in 1920, the NFL developed the model for the successful modern sports league, including national and international distribution, extensive revenue sharing, competitive excellence, and strong franchises across the country.\n\nThe NFL is committed to advancing progress in the diagnosis, prevention and treatment of sports-related injuries. The NFL's ongoing health and safety efforts include support for independent medical research and engineering advancements and a commitment to look at anything and everything to protect players and make the game safer, including enhancements to medical protocols and improvements to how our game is taught and played.\n\nAs more is learned, the league evaluates and changes rules to evolve the game and try to improve protections for players. Since 2002 alone, the NFL has made 50 rules changes intended to eliminate potentially dangerous tactics and reduce the risk of injuries.\n\nFor more information about the NFL's health and safety efforts, please visit www.PlaySmartPlaySafe.com."},{"metadata":{"trusted":true,"_uuid":"f86d7d2181c19e4a6be5edc89c4bb7357a246f6f"},"cell_type":"markdown","source":"# <a id='importing'><b>2 Importing and installing dependencies:</b></a>"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"%matplotlib inline\n\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport warnings\n\nwarnings.simplefilter(action='ignore', category=FutureWarning)\nsns.set()\n\nprint('All dependencies installed')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"c6797be4018acf2e27ca56f09024aca74c3a4af7"},"cell_type":"markdown","source":"# <a id='game_data'><b>3 Game Data:</b></a>"},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"def lower_case(dataset):\n    dataset.columns = [col.lower() for col in dataset.columns]\n    return dataset\n\ngame_data = pd.read_csv('../input/game_data.csv', parse_dates=True)\ngame_data = lower_case(game_data)\nprint(game_data.shape)\ngame_data.head()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"f9b9dcb21d2a9a94605151f93e3b22f3fda4f13e"},"cell_type":"markdown","source":"## <a id='null'><b>3.1 Checking for Null values</b></a>"},{"metadata":{"trusted":true,"_uuid":"3ca6927efa55c18ffff459219e82763594e427f7","_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"def num_missing(x):\n  return print('Missing values per column:\\n', np.sum(x.isnull()))\n\nnum_missing(game_data)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"7981144364ea5e19515e09bf80d800ab7355f049"},"cell_type":"markdown","source":"### <a id='null_needs'>3.1.1 Checking whether or not we need the columns with missing values</a>"},{"metadata":{"trusted":true,"_uuid":"0dcf24d0f1082beb38bed2d14856a101793ab6e1","_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"stadium_type = game_data['stadiumtype'].value_counts()\nturf = game_data['turf'].value_counts()\ngame_weather = game_data['gameweather'].value_counts()\ntemperature = game_data['temperature'].value_counts()\noutdoor_weather = game_data['outdoorweather'].value_counts\n\nprint(stadium_type, '\\n', '-'*50, '\\n', turf, '\\n', '-'*50, '\\n', game_weather, '\\n', '-'*50, '\\n', temperature,  '\\n', '-'*50, '\\n', outdoor_weather)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"f072541060f16c2b1cf06513a822f40394c2699b"},"cell_type":"markdown","source":"stadium_type = most of the values are repeated or labelled differently but mean the same. Most stadiums also are outdoors with a few with retractable roofs. The few that are missing can be searched easily. \nturf = same with stadium_type, most values are the same but labelled differently and can be searched easily. \ngame_weather = around 15% of the values are missing in this column. This can be searched but will be more time-consuming. \ntemperature = around 10% of the values are missing in this column, which seems a little weird since game_weather has more missing values. \noutdoor_weather = around 38% of the data is missing and may potentially not have a very big impact on the analysis of data."},{"metadata":{"trusted":true,"_uuid":"3c6838400ad6e184f7948cb19ad64f1b21c7d241"},"cell_type":"markdown","source":"<a id='null_drop'>3.1.2 Dropping unnecessary columns</a>"},{"metadata":{"trusted":true,"_uuid":"8845cdc08506c6e952a9c8993ea3ba21e5d02290","_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"game_data = game_data.drop(columns=['outdoorweather', 'gameweather'], axis=1)\ngame_data.info()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"3b3eacb9ebac67187b7cf09400f2fcbb91e15bcb"},"cell_type":"markdown","source":"After dropping 2 columns and changing their types, the memory usage went down by 21+ KB"},{"metadata":{"_uuid":"f46ce43374bc89ecd763571fec1818eceff60ea1"},"cell_type":"markdown","source":"## <a id='types'><b>3.2 Checking column types</b></a>"},{"metadata":{"trusted":true,"_uuid":"19bffd5a007a2308aa1cf760d71f2858dd94e2a4","_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"game_data.info()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"e54b786d3a3758d14a0a03ccdeb9c7af269b4665"},"cell_type":"markdown","source":"### <a id='memory_usage'> 3.2.1 Changing column types for less memory usage</a>"},{"metadata":{"trusted":true,"_uuid":"a84fea94b1cf25f903f531434dd8bf4be48368f2","_kg_hide-input":true,"_kg_hide-output":false},"cell_type":"code","source":"category_columns = ['season_type', 'stadiumtype', 'turf']\nfloat_columns = ['temperature']\n\ngame_data[category_columns] = game_data[category_columns].astype('category')\ngame_data[float_columns] = game_data[float_columns].astype(float)\ndate = pd.to_datetime(game_data['game_date'].str.split(expand=True)[0], format='%Y-%m-%d')\n\ngame_data.info()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"c519f005ba4deb9c632e6e059f05aa397f88cf28"},"cell_type":"markdown","source":"## <a id='scatter_plot'><b>3.3 Plotting the games of the season</b></a>"},{"metadata":{"trusted":true,"_uuid":"53b1aaf3e7e336793b756df4863fc23b84feaf4c","_kg_hide-input":true},"cell_type":"code","source":"plt.figure(figsize=(20, 9))\n\n_ = sns.scatterplot(x='home_team', y='visit_team', hue='week',data=game_data)\nplt.xticks(rotation=90, fontsize=14)\nplt.yticks(fontsize=15)\nplt.xlabel('Visiting Team')\nplt.ylabel('Home Team')\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8ab68884afe925004ca48f2a261adf78e64d6818"},"cell_type":"markdown","source":"It seems that the dataset included for NFC and AFC which are divisions and not teams."},{"metadata":{"trusted":true,"_uuid":"3c1cdfaa69718cbeef5a64e41665ccaf35aff7b3"},"cell_type":"markdown","source":"# <a id='video_footage_injury'><b>4 Video Footage Injury:</b></a>"},{"metadata":{"trusted":true,"_uuid":"4aacc1ae896201d798be5c505d14d625791a8994","_kg_hide-input":true},"cell_type":"code","source":"video_footage_injury = pd.read_csv('../input/video_footage-injury.csv', parse_dates=True)\nvideo_footage_injury = lower_case(video_footage_injury)\nprint(game_data.shape)\nvideo_footage_injury.head()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"f0ef032ac632601a331e2a13b27cc0321ed423dd"},"cell_type":"markdown","source":"## <a id='video_footage_injury_null'><b>4.1 Checking for Null values</b></a>"},{"metadata":{"trusted":true,"_uuid":"fc928dcb82a5c548c8829da6070bccfd2ae40475","_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"num_missing(video_footage_injury)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"da3f6b84eb16188da41aaa1686c9b73c879a64f4"},"cell_type":"markdown","source":"## <a id='video_footage_injury_types'><b>4.2 Checking column types</b></a>"},{"metadata":{"trusted":true,"_uuid":"6238872623476c0b757a9413630a8ba818c4c6ef","_kg_hide-input":true,"_kg_hide-output":false},"cell_type":"code","source":"video_footage_injury.info()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"b71c260909ffd185018775ee5ca0d2950473ffac"},"cell_type":"markdown","source":"## <a id='video_footage_injury_season'><b>4.3 Plotting concussions by season and year</b></a>\n### <a id='video_footage_injury_season_season'>4.3.1 Concussions by season and year</a>"},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"bd7b01255e66b5729252852c53d11137f5e953e5","_kg_hide-input":true},"cell_type":"code","source":"plt.figure(figsize=(20, 7.5))\n\nplt.subplot(1, 2, 1)\n_ = sns.countplot(video_footage_injury['type'])\nplt.title('Concussions per season type:', fontsize=20)\nplt.xticks(fontsize=15)\nplt.yticks(fontsize=15)\nplt.xlabel('Type of season', fontsize=15)\nplt.ylabel('Total amount of concussions', fontsize=15)\n\nplt.subplot(1, 2, 2)\n_ = sns.countplot(video_footage_injury['season'])\nplt.title('Concussions per year:', fontsize=20)\nplt.xticks(fontsize=15)\nplt.yticks(fontsize=15)\nplt.xlabel('Year', fontsize=15)\nplt.ylabel('Total amount of concussions', fontsize=15)\n\nplt.tight_layout()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"a2896f68bafdf4c4aae1b373749c7a7e87560235"},"cell_type":"markdown","source":"Clearly, more of the concussions occur during regular season rather than the pre-season and 2016 is showing a slight increase in concussions."},{"metadata":{"_uuid":"6916cb711e0b6743b5d9ae6d409e83abcd02d6e5"},"cell_type":"markdown","source":"### <a id='video_footage_injury_season_week'>4.3.2 Concussions by week and quarter</a>"},{"metadata":{"trusted":true,"_uuid":"e5b38530d677fc2c6e80df235baa740c848a6d7d","_kg_hide-input":true},"cell_type":"code","source":"plt.figure(figsize=(20, 10))\n\nplt.subplot(2, 1, 1)\n_ = sns.swarmplot(x='week', y='type', hue='qtr', data=video_footage_injury)\nplt.title('Concussions per week:', fontsize=20)\nplt.xticks(fontsize=15)\nplt.yticks(fontsize=15)\nplt.xlabel('Week', fontsize=15)\nplt.ylabel('Season Type', fontsize=15)\n\nplt.subplot(2, 1, 2)\n_ = sns.boxplot(x='qtr', y='week', data=video_footage_injury)\nplt.title('Concussions per quarter:', fontsize=20)\nplt.xticks(fontsize=15)\nplt.yticks(fontsize=15)\nplt.xlabel('Week', fontsize=15)\nplt.ylabel('')\n\nplt.tight_layout()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"30c6fe55d566724ca23b5e2a486ac7e1af9501c0"},"cell_type":"markdown","source":"It seems that as the season gets in its final stages, concussions are more prevalent. This can be correlated to teams trying to make it to the playoffs rather than getting eliminated. Also, most concussions occur during the 4th quarter followed by the 2nd quarter. The 1st, 2nd, and 3rd quarters show almost an identical distribution."},{"metadata":{"trusted":true,"_uuid":"0e2a603aeb91f54432264131632867f7d0cf8e36"},"cell_type":"markdown","source":"# <a id='video_review'><b>5 Video Review:</b></a>"},{"metadata":{"trusted":true,"_uuid":"f3d698fbf0ee95022c4bbb513824ada09108c74e","_kg_hide-input":true},"cell_type":"code","source":"video_review = pd.read_csv('../input/video_review.csv')\nvideo_review = lower_case(video_review)\nprint(video_review.shape)\nvideo_review.head()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"ead618a764e394e6e912f900761d0e7232cffc86"},"cell_type":"markdown","source":"## <a id='video_review_null'><b>5.1 Checking for Null values</b></a>"},{"metadata":{"trusted":true,"_uuid":"2018ccd6f8c311c6383cb1e5a17dfdab207db0db","_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"num_missing(video_review)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"293ae2564537d6f35d5c8f338c0e0069e745251c"},"cell_type":"markdown","source":"### <a id='video_review_null_needs'>5.1.1 Checking whether or not we need the columns with missing values</a>"},{"metadata":{"_uuid":"16908d877c4c3206b70ca3670dd6fa91d0d88e11","trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"video_review = video_review.drop(columns=['primary_partner_gsisid'], axis=1)\nvideo_review = video_review.dropna()\nvideo_review.info()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"a7ef178e78dd79c3c4572d513391a8d1d6a2c4ad"},"cell_type":"markdown","source":"Decided to drop the column 'Primary_Partner_GSISID' that was not relevant and drop 2 rows missing values."},{"metadata":{"trusted":true,"_uuid":"ad41e616326289f8e166e8e4f60acc143cb1f933"},"cell_type":"markdown","source":"## <a id='video_review_types'><b>5.2 Checking column types</b></a>"},{"metadata":{"trusted":true,"_uuid":"ea03a59e54ed9ade72f54e24a6fea918244fa20d","_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"video_review.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8c8e7ef545f6cd9c83d7447a4f8d1bd21ad335fc"},"cell_type":"markdown","source":"### <a id='video_review_usage'> 5.2.1 Changing column types for less memory usage</a>"},{"metadata":{"trusted":true,"_uuid":"9996ee383b2e5867bd9777522f37b092c7229354","_kg_hide-input":true},"cell_type":"code","source":"category_columns = ['player_activity_derived', 'turnover_related', 'primary_impact_type', 'primary_partner_activity_derived', 'friendly_fire']\n\nvideo_review[category_columns] = video_review[category_columns].astype('category')\nvideo_review.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"db07c6802bdfdbc87ecc125c7bd4eced70de1d27"},"cell_type":"markdown","source":"Dropping one of the columns and changing the type of 5 columns, memory usage was brought down by 0.5KB."},{"metadata":{"trusted":true,"_uuid":"2fbad58e96864e13d0f1e653e623f9ff588cdc38"},"cell_type":"markdown","source":"## <a id='video_review_plot'><b>5.3 Plotting concussions by category</b></a>"},{"metadata":{"trusted":true,"_uuid":"a7366dcef26a1c1ae8c3c33adb16596bc7bbbcb7","_kg_hide-input":true},"cell_type":"code","source":"plt.figure(figsize=(20, 7.5))\n\nplt.subplot(1, 2, 1)\n_ = sns.countplot(video_review['player_activity_derived'])\nplt.title('Concussions related incidents:', fontsize=20)\nplt.xlabel('')\nplt.ylabel('')\nplt.xticks(fontsize=15)\nplt.yticks(fontsize=15)\n\nplt.subplot(1, 2, 2)\n_ = sns.countplot(video_review['friendly_fire'])\nplt.title('Incidents from same team or opposing:', fontsize=20)\nplt.xlabel('')\nplt.ylabel('')\nplt.xticks([0, 1, 2], ['Opposing Team', 'Unclear', 'Same Team'], fontsize=15)\nplt.yticks(fontsize=15)\n\nplt.tight_layout()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"477798832c0642a3f2ec20aa959f2cf2b8a8385f"},"cell_type":"markdown","source":"Most concussions occur while tackling a player from the opposed team. Maybe new rules could be applied on the players that are tackling in order to lower the incedents rate."},{"metadata":{"trusted":true,"_uuid":"b78c4595d3426e09749f3a8de267f9a0e38e66b5"},"cell_type":"markdown","source":"# <a id='video_footage_control'><b>6 Video Footage Control:</b></a>"},{"metadata":{"trusted":true,"_uuid":"1dbf6ea0714dba0e98d3347fec23358e95bdaecc","_kg_hide-input":true},"cell_type":"code","source":"video_footage_control = pd.read_csv('../input/video_footage-control.csv')\nvideo_footage_control = lower_case(video_footage_control)\nprint(video_footage_control.shape)\nvideo_footage_control.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5e876c089991e2edee1ad37e83ae74759391d4d1"},"cell_type":"markdown","source":"## <a id='video_footage_control_null'><b>6.1 Checking for Null values</b></a>"},{"metadata":{"trusted":true,"_uuid":"b80f6fe0da7fcb56307e11ee31d9e303bdf05136","_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"num_missing(video_footage_control)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"4eba944e62478978c8cfbffaaf879cc2d5beb635"},"cell_type":"markdown","source":"## <a id='video_footage_control_types'><b>6.2 Checking column types</b></a>"},{"metadata":{"trusted":true,"_uuid":"7f20a63863b4dd765edea39a7da782de5ef9353e","scrolled":true,"_kg_hide-input":true,"_kg_hide-output":false},"cell_type":"code","source":"video_footage_control.info()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"78bc9ee6f73f62cd3e0a802d5c199efb43c410d4"},"cell_type":"markdown","source":"## <a id='video_footage_control_types_plot'><b>6.3 Plotting video reviews by quarter</b></a>"},{"metadata":{"trusted":true,"_uuid":"d879653bf4a54f1da9c0d8d39e50714bd562af82","_kg_hide-input":true},"cell_type":"code","source":"quarter_count = video_footage_control['qtr'].value_counts()\n\nplt.figure(figsize=(20, 7.5))\n\n_ = sns.scatterplot(x='qtr', y='home_team', data=video_footage_control)\nplt.title('Distributions of injuries per quarter:', fontsize=20)\nplt.xlabel('Quarter', fontsize=15)\nplt.ylabel('')\nplt.xticks([1, 2, 3, 4], fontsize=15)\nplt.yticks(fontsize=15)\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"1a0889d361e36cd9558cdd06366259c9da898d8a"},"cell_type":"markdown","source":"In the 'video_footage_control', most reviews occur in the 1st quarter and most teams show a similar amount of reviews."},{"metadata":{"trusted":true,"_uuid":"4f0994b378addd22c8c23dab1bd6d7980b2a61de"},"cell_type":"markdown","source":"# <a id='play_information'><b>7 Play Information:</b></a>"},{"metadata":{"trusted":true,"_uuid":"1b85a02af695cc2b27a6927a47ab2e3bc4d3a9c7","_kg_hide-input":true},"cell_type":"code","source":"play_information = pd.read_csv('../input/play_information.csv')\nplay_information = lower_case(play_information)\nprint(play_information.shape)\nplay_information.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f9cf1c2e00b49c8401a71ac1beb7ceed05c85e37"},"cell_type":"markdown","source":"## <a id='play_information_null'><b>7.1 Checking for Null values</b></a>"},{"metadata":{"trusted":true,"_uuid":"eb50b954075a30be66f296be9ce4e36ac30baaaa","_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"num_missing(play_information)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2d20074d5116897614f3f7ecd839e7f2d51aff6a"},"cell_type":"markdown","source":"## <a id='play_information_types'><b>7.2 Checking column types</b></a>"},{"metadata":{"trusted":true,"_uuid":"bc531a45a2bb510957929c9cefe627a7ea5ad58f","_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"play_information.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3948f9ddb261fcb648429dc642426168cb195c8e","_kg_hide-input":true},"cell_type":"code","source":"category_columns = ['season_type']\nplay_information[category_columns] = play_information[category_columns].astype('category')\nplay_information['game_clock'] = pd.to_datetime(play_information['game_clock'], format='%H:%M').dt.time\nplay_information.info()\nplay_information.head()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"ff2f9bac8eaa92f682058ef4d8037a4c64589b7a"},"cell_type":"markdown","source":"## <a id='play_information_types_plot'><b>7.3 Plotting total amount of plays per week</b></a>"},{"metadata":{"trusted":true,"_uuid":"3a7a52103775340b0c4bdf242ecc91c4ab476512","_kg_hide-input":true},"cell_type":"code","source":"plt.figure(figsize=(20, 7.5))\n\n_ = sns.countplot(play_information['week'])\n# _ = sns.swarmplot(x='Week', y='YardLine', data=play_information, hue='Poss_Team')\nplt.title('Total amount of plays per week:', fontsize=20)\nplt.xticks(fontsize=15)\nplt.yticks(fontsize=15)\nplt.xlabel('Week', fontsize=15)\nplt.ylabel('')\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"ea9ccbb59ad28053775bd5c983fa6e756251f02e"},"cell_type":"markdown","source":"The average of plays made during the season is pretty even to each other an exception to the 2nd through the 5th week; which jumps to almost double than the closest one."},{"metadata":{"trusted":true,"_uuid":"98804d54f36b85b72be627e9a09a21174e7b1957"},"cell_type":"markdown","source":"# <a id='play_player_role_data'><b>8 Play Player Role Data:</b></a>"},{"metadata":{"trusted":true,"_uuid":"5fd3cd0ad215e6d9a0ab7c75581bb95400797abf","_kg_hide-input":true},"cell_type":"code","source":"play_player_role_data = pd.read_csv('../input/play_player_role_data.csv')\nplay_player_role_data = lower_case(play_player_role_data)\nprint(play_player_role_data.shape)\nplay_player_role_data.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c63e21f55ca656b59ce039bba485ff3abd095e90"},"cell_type":"markdown","source":"## <a id='play_player_role_data_null'><b>8.1 Checking for Null values</b></a>"},{"metadata":{"trusted":true,"_uuid":"6d1f8fe71597b4f4f0139547d9a0ab24b01e8601","_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"num_missing(play_player_role_data)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ed3b00a8bef3937c6b8d69ddaf867d0e3726d952"},"cell_type":"markdown","source":"## <a id='play_player_role_data_types'><b>8.2 Checking column types</b></a>"},{"metadata":{"trusted":true,"_uuid":"db22b993cbab63c0e508aa5d1dee4ac78f187a7b","_kg_hide-input":true},"cell_type":"code","source":"play_player_role_data.info()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"e0290e91e13a8ea8e68a215187d8abd982f3889d"},"cell_type":"markdown","source":"## <a id='play_player_role_data_plot'><b>8.3 Plotting amount of players per role</b></a>"},{"metadata":{"trusted":true,"_uuid":"66534ace0e9946ec49197370031a1dc6d795cb1a","_kg_hide-input":true},"cell_type":"code","source":"plt.figure(figsize=(20, 7.5))\n\n_ = sns.countplot(play_player_role_data['role'])\nplt.title('Counting the total amount of players in each position per play:', fontsize=20)\nplt.xticks(rotation=90, fontsize=15)\nplt.yticks(fontsize=15)\nplt.xlabel('Role', fontsize=15)\nplt.ylabel('')\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"21e7a5be9d08e495024309c4d4b087d488c99730"},"cell_type":"markdown","source":"This chart should NOT be confused with the total number of players in each position since each row is separated by play and not a game. Many plays can occur in each match."},{"metadata":{"_uuid":"e4a5197c73d994e4575f1a8b21665795ac60acb7"},"cell_type":"markdown","source":"# <a id='player_punt_data'><b>9 Player Punt Data:</b></a>"},{"metadata":{"trusted":true,"_uuid":"b2f80ef6f6cfdbb5eb251d45afcb8e414af5bbc4","_kg_hide-input":true},"cell_type":"code","source":"player_punt_data = pd.read_csv('../input/player_punt_data.csv')\nplayer_punt_data = lower_case(player_punt_data)\nprint(player_punt_data.shape)\nplayer_punt_data.head()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"0c653f3108aa99b61b0e1792459731c9735527da"},"cell_type":"markdown","source":"## <a id='player_punt_data_null'><b>9.1 Checking for Null values</b></a>"},{"metadata":{"trusted":true,"_uuid":"8ae7b2f12572e726f559fce05eba7de7faf71f01","_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"num_missing(player_punt_data)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"a02c28525c4d5bc88e452b31104e4fd491912c21"},"cell_type":"markdown","source":"## <a id='player_punt_data_types'><b>9.2 Checking column types</b></a>"},{"metadata":{"trusted":true,"_uuid":"c323e2097de5800e0e14d6c8d2d0582950911312","_kg_hide-input":true},"cell_type":"code","source":"player_punt_data.info()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"dacc6e6eabedd1c13b5e6ef97d1ed2bac9a9071e"},"cell_type":"markdown","source":"## <a id='player_punt_data_plot'><b>9.3 Plotting each players position</b></a>"},{"metadata":{"trusted":true,"_uuid":"4394c1d48fe2854eb7690a03bab1f245524cee01","_kg_hide-input":true},"cell_type":"code","source":"plt.figure(figsize=(20, 7.5))\n\n_ = sns.countplot(player_punt_data['position'])\nplt.title('Count of each individual position:', fontsize=20)\nplt.xticks(fontsize=15)\nplt.yticks(fontsize=15)\nplt.xlabel('Positions', fontsize=15)\nplt.ylabel('')\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d1e2e5374063a95bcdf3a6e529d0f8ceb896bbf5"},"cell_type":"markdown","source":"After importing, plotting and analyzing each of the datasets, I can see that some datasets can be combined in order to have a better picture of the overall injuries."},{"metadata":{"trusted":true,"_uuid":"bae9b49b2f0812faa2ed35eb1b9c74a75300462c"},"cell_type":"markdown","source":"# <a id='player_data'><b>10 Player Data:</b></a>"},{"metadata":{"trusted":true,"_uuid":"00708c535bbd3cb223da93c275cd4f6de79e4000","_kg_hide-input":true},"cell_type":"code","source":"player_data = pd.merge(play_player_role_data, player_punt_data)\nplayer_data = pd.merge(player_data, play_information)\nplayer_data = pd.merge(player_data, video_review)\nplayer_data.head()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"33456d2fd97d0a0ba223679218bcd878e706a6a5"},"cell_type":"markdown","source":"## <a id='player_data_plotting_injuries'><b>10.1 Plotting injuries from punts</b></a>"},{"metadata":{"trusted":true,"_uuid":"a09c4abf4cc565587aaeef91429f9c992f4c6b6b","_kg_hide-input":true},"cell_type":"code","source":"player_data = player_data.sort_values('poss_team')\n\nplt.figure(figsize=(20, 7.5))\n\n_ = sns.countplot(player_data['poss_team'])\nplt.title('Teams that suffered injuries from punts:', fontsize=20)\nplt.xticks(fontsize=15)\nplt.yticks(fontsize=15)\nplt.xlabel('', fontsize=15)\nplt.ylabel('Possesing Team', fontsize=15)\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"2e9edbb5bd00e46c6edd61602cdda43992d5d4f1"},"cell_type":"markdown","source":"Interestingly, Green Bay seems to get all its injuries through blocks; whereas other teams tackling and blocking are the main factors. The tackler rarely gets injured; therefore, we can concentrate on making rules that will protect the person that is getting tackled or blocked and penalizing very aggressive tacklers."},{"metadata":{"trusted":true,"_uuid":"9d65ae920cca7e0f5cef87fc8c5f2212f12d1b47"},"cell_type":"code","source":"plt.figure(figsize=(20, 7.5))\n\n_ = sns.countplot(y=player_data['player_activity_derived'], hue=player_data['poss_team'])\nplt.title('Activity when suffering injuries from punts:', fontsize=20)\nplt.xticks(fontsize=15)\nplt.yticks(fontsize=15)\nplt.xlabel('', fontsize=15)\nplt.ylabel('Player Activity Derived', fontsize=15)\nplt.legend(fontsize=15)\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"be1096a552c3aba80046fc3f4c66a15e34c712fa"},"cell_type":"markdown","source":"## <a id='player_data_plotting_aggressive_teams'><b>10.2 Plotting most aggressive teams</b></a>"},{"metadata":{"trusted":true,"_uuid":"ca40b6615e8882895a4c1141417c374d001ca986","_kg_hide-input":true},"cell_type":"code","source":"plt.figure(figsize=(20, 7.5))\n\n_ = sns.countplot(player_data['home_team_visit_team'], hue=player_data['player_activity_derived'])\nplt.title('Analyzing if teams play more aggressively against others:', fontsize=20)\nplt.xticks(rotation=90, fontsize=15)\nplt.yticks(fontsize=15)\nplt.xlabel('Possesing Team', fontsize=15)\nplt.ylabel('')\nplt.legend(fontsize=15)\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"02a5d6d22976d9a36f25fae398e7cba0615d9ab4"},"cell_type":"markdown","source":"Some teams play more aggressively than others, like WAS. Maybe fines can be implemented to teams that constantly injure players more than average."},{"metadata":{"_uuid":"3a35c6d6873fa8d7cccdb0bbd964c87a66f441fd"},"cell_type":"markdown","source":"## <a id='player_data_plotting_locations'><b>10.3 Plotting location of injuries in the field</b></a>"},{"metadata":{"trusted":true,"_uuid":"84579a5e7d095780cfedfdd00b7f709408cdc02a","_kg_hide-input":true},"cell_type":"code","source":"player_data['yard'] = player_data['yardline'].str.split(' ').str[1].astype(int)\nplayer_data.sort_values(by=['yard'], inplace=True)","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"trusted":true,"_uuid":"4e13c33732b97c5ad69d8cb9d6e8f4ae60fbafb0"},"cell_type":"code","source":"plt.figure(figsize=(20, 10))\n\nplt.subplot(2, 1, 1)\n_ = sns.countplot(player_data['yard'])\nplt.title('Analyzing location of injuries:', fontsize=20)\nplt.xticks(rotation=90, fontsize=15)\nplt.yticks(fontsize=15)\nplt.xlabel('Yard', fontsize=15)\nplt.ylabel('')\nplt.legend(fontsize=15, loc=1)\n\nplt.subplot(2, 1, 2)\n_ = sns.swarmplot(x='poss_team', y='yard', data=player_data, hue='quarter', s=7.5, palette=['Green', 'Blue', 'Orange', 'Red'])\nplt.title('Analyzing location of injuries by team:', fontsize=20)\nplt.xticks(rotation=90, fontsize=15)\nplt.yticks(fontsize=15)\nplt.xlabel('Possesing Team', fontsize=15)\nplt.ylabel('Yard', fontsize=15)\nplt.legend(fontsize=15)\n\nplt.tight_layout()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"0519749091bbbdf4b4c018ec1db8d2670fc9539f"},"cell_type":"markdown","source":"There is a slight correlation of injuries occurring between the 20th and 30th-yard line, as the team gets closer to the red zone. Surprisingly, only a few were marked in the red zone and a slight more were in the teens. Also, there are some teams that display more injuries than others. A"},{"metadata":{"_uuid":"3b22439df080d61e732645036fd423de293cca34"},"cell_type":"markdown","source":"## <a id='player_data_plotting_time'><b>10.4 Plotting time of injuries</b></a>"},{"metadata":{"trusted":true,"_uuid":"4d99e15f0e3104f056ea08d5d9ff5cc0178acc5e","_kg_hide-input":true},"cell_type":"code","source":"player_data.sort_values(['quarter', 'game_clock'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1032f7ba0ce1857ce008b80094b0c81cfad7194f"},"cell_type":"code","source":"plt.figure(figsize=(20, 7.5))\n\n_ = sns.barplot(x='game_clock', y=range(16), data=player_data)\nplt.xticks(rotation=90)\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"bce060e0700e243697339e04f5af4dcc14d69eac"},"cell_type":"markdown","source":"Not surprising, as the clock winds down; the change of injury slowly increments."},{"metadata":{"trusted":true,"_uuid":"a6eca4ed3a29ad7008e2b69229cb3781e9ce7965"},"cell_type":"markdown","source":"* # <a id='play_data'><b>11 Play Data:</b></a>"},{"metadata":{"trusted":true,"_uuid":"bb6a4d2e1838290c853399c0d83581e456bb9255"},"cell_type":"code","source":"play_data = pd.merge(play_information, game_data, on='gamekey')\nprint(play_data['playdescription'][0])\nprint(play_data['playdescription'][1])\nprint(play_data['playdescription'][2])\nprint(play_data['playdescription'][3])\nprint(play_data['playdescription'][4])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b9ab917f667d220c3e6acfacb7f59306ad40a680"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2b1532cc2615138f84a2c9e3b235ee79a3c14a9a"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5ed167b87912bd0492ff2adf008f85ed141483f6"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"461371c3f5cdf831633c701a46249a7df7974517"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}