{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"import matplotlib.pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6944dd3bb57fae87fd0400342d78b29b8c9deaf6"},"cell_type":"code","source":"pd.set_option('display.max_columns', None)\npd.set_option('display.max_colwidth', -1)","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-output":false,"_kg_hide-input":false,"trusted":true,"_uuid":"d979fda21e2d251b68f0e70ce66cd90a3de36a79"},"cell_type":"code","source":"play_player_role_data = pd.read_csv(\"../input/play_player_role_data.csv\")\ngame_data = pd.read_csv('../input/game_data.csv')\nplay_info = pd.read_csv('../input/play_information.csv')\nplayer_punt_data = pd.read_csv('../input/player_punt_data.csv')\nvideo_review = pd.read_csv('../input/video_review.csv')\nngs_pre_2016 = pd.read_csv('../input/NGS-2016-pre.csv')\nngs_reg_2016_1 = pd.read_csv('../input/NGS-2016-reg-wk1-6.csv')\nngs_reg_2016_2 = pd.read_csv('../input/NGS-2016-reg-wk7-12.csv')\nngs_reg_2016_3 = pd.read_csv('../input/NGS-2016-reg-wk13-17.csv')\nngs_post_2016 = pd.read_csv('../input/NGS-2016-post.csv')\nngs_pre_2017 = pd.read_csv('../input/NGS-2017-pre.csv')\nngs_reg_2017_1 = pd.read_csv('../input/NGS-2017-reg-wk1-6.csv')\nngs_reg_2017_2 = pd.read_csv('../input/NGS-2017-reg-wk7-12.csv')\nngs_reg_2017_3 = pd.read_csv('../input/NGS-2017-reg-wk13-17.csv')\nngs_post_2017 = pd.read_csv('../input/NGS-2017-post.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2db182406de5263eedcbccf872c242f596183aac"},"cell_type":"code","source":"len(play_info)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"558f00ab3f1683ce6e4f475e8206b9795a7f2221"},"cell_type":"code","source":"len(video_review)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"13d0bbef9beaac577925843789928e608c2e6bee"},"cell_type":"markdown","source":"37 of 6681 total plays resulted in one or more concussion. With player safety in mind that is a small number, thankfully. But the small number in itself proposes a challenge analytically. The concussion related data is sparse and prone to o overengineering with no statistically valid data."},{"metadata":{"trusted":true,"_uuid":"74f4f0f0a9e5ac5c2de72029b7a2ebbe3523de31"},"cell_type":"code","source":"ax = video_review['Player_Activity_Derived'].value_counts().plot(kind='bar', title =\"Activity\", figsize=(15, 10), fontsize=12)\nax.set_xlabel(\"Activity\", fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0b62c4e898fea2d837f9d518ac25cdc03a95ba7b"},"cell_type":"markdown","source":"Tackling and getting blocked account for most of the concussions, followed by blocking and getting tackled. That seems a bit counter-intuitive: When one thinks of highlight reel worthy hard impacts on punt plays, Punt Returners getting hit in the moment of catching the ball come to mind. Might still be true but the player tackling seem to be more in danger of suffering a concussion. Before we look into that, let's see which type of contact causes concussions."},{"metadata":{"trusted":true,"_uuid":"18c6257061957fe842701df51530adda5c678d0d"},"cell_type":"code","source":"ax = video_review['Primary_Impact_Type'].value_counts().plot(kind='bar', title =\"Impact Type\", figsize=(15, 10), fontsize=12)\nax.set_xlabel(\"Type of Collision\", fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"52d7df89df4028d508bbd1f96d5d6993b4587685"},"cell_type":"markdown","source":"Thinking of concussions bone crushing helmet-to-helmet hits come to mind. The NFL did a lot of things to prevent helmet to helmet collisions in the past, so somewhat surprisingly helmet to body hits cause the same amount of concussions.","attachments":{}},{"metadata":{"trusted":true,"_uuid":"573fd80bcca9879deb09b54d58c136f629044dfa"},"cell_type":"code","source":"play_player_role_data['identifier'] = play_player_role_data['GameKey'].astype(str) + \"_\" + play_player_role_data['PlayID'].astype(str)\nvideo_review['identifier'] = video_review['GameKey'].astype(str) + \"_\" + video_review['PlayID'].astype(str)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"49cf33689a54d2133a5fe304d82efe2d24a63603"},"cell_type":"code","source":"play_info['identifier'] = play_info['GameKey'].astype(str) + \"_\" + play_info['PlayID'].astype(str)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d8a8946b20026b9dee41321bd136121593d3ef25"},"cell_type":"code","source":"play_injuries = video_review.merge(play_info, left_on='identifier', right_on='identifier', how='inner')\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9b7ec141f23db7ebc0215012a3775fd4265e98fc"},"cell_type":"code","source":"fc = 'fair catch'\nfair_catch = play_injuries.PlayDescription.str.count(fc).sum()\nmuff = 'MUFFS'\nmuffed = play_injuries.PlayDescription.str.count(muff).sum()\ntb = 'Touchback'\ntouchback = play_injuries.PlayDescription.str.count(tb).sum()\ndown = 'downed'\ndowned = play_injuries.PlayDescription.str.count(down).sum()\nob = 'out of bounds'\nout_of_bounds = play_injuries.PlayDescription.str.count(ob).sum()\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"42761132d4e48e0ef8536839bd61ce431eac0df9"},"cell_type":"code","source":"returned = len(play_injuries) - fair_catch - muffed - touchback - downed - out_of_bounds","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"058b1794fca9d46f37d470e80e9d904c04af85d1"},"cell_type":"code","source":"play_result_conc = pd.DataFrame({'touchback': [touchback], 'Fair Catch': [fair_catch], 'muffed': [muffed], 'out_of_bounds': [out_of_bounds], 'downed': [downed], 'returned': [returned]})","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2e83dac04ff85643a7a1111740b3c3f9cb904eee"},"cell_type":"code","source":"ax = play_result_conc.plot(kind='bar', title =\"Result o Play\", figsize=(15, 10), fontsize=12)\nax.set_xlabel(\"Result\", fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"99b5de36853cba02e8ae9cde647a8074eaf5ebbe"},"cell_type":"markdown","source":"Not surprisingly, plays that are returned account for most of the concussions.","attachments":{}},{"metadata":{"trusted":true,"_uuid":"1401fc8b48b94cbf719d79ff7384ac28e53692c6"},"cell_type":"code","source":"play_player_role_data['identifier'] = play_player_role_data['GameKey'].astype(str) + \"_\" + play_player_role_data['PlayID'].astype(str)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a1cd3cbacac2e495d601900435d6edf3f1d3699b"},"cell_type":"code","source":"player_injured = play_injuries.merge(play_player_role_data, how='inner', on=['identifier', 'GSISID'])\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"331485b4148a2bd3b409920a1224b329027bd531"},"cell_type":"code","source":"ax = player_injured.Role.value_counts().plot(kind='bar', title =\"Role of Player\", figsize=(15, 10), fontsize=12)\nax.set_xlabel(\"Role\", fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"35bbaba16dd81504ee31feabee8e946cb7403131"},"cell_type":"markdown","source":"As one of the key players during punts, it meets expectations that Punt Returners are the position most involved in plays resulting in a concussion."},{"metadata":{"trusted":true,"_uuid":"5dff2ab3b1e5c6ae7f7eb9eca1ab52c0e928daa1"},"cell_type":"code","source":"return_team = player_injured.Role.isin(['PDL1','PDL2','PDL3','PDL4','PDL5','PDL6','PDM','PDR1','PDR2','PDR3','PDR4','PDR5','PDR6'\n                ,'PFB','PLL','PLL1','PLL2','PLL3','PLM','PLM1','PLR','PLR1','PLR2','PLR3','PR','VL','VLi'\n                ,'VLo','VR','VRi','VRo']).sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f49a55cacfdd01a2ac9c10bf976734ac50791f4c"},"cell_type":"code","source":"punt_team = player_injured.Role.isin(['GL','GLi','GLo','GR','GRi','GRo','P','PC','PLG','PLS','PLT','PLW','PPL','PPLi','PPLo'\n                 ,'PPR','PPRi','PPRo','PRG','PRT','PRW']).sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ce4e88e3d91080688bdc0dde1419b46c3e768062"},"cell_type":"code","source":"teams = pd.DataFrame({'Returning Team': [return_team], 'Punting Team': [punt_team]})","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"06b3f926b98a7e0696185d61bfa993204b2646c5"},"cell_type":"code","source":"ax = teams.plot(kind='bar', title =\"Side o Ball w Conc\", figsize=(15, 10), fontsize=12)\nax.set_xlabel(\"Team\", fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"794cc4282600fad39029805a3e753d15ce19ff83"},"cell_type":"markdown","source":"In accordance with the results of player activity during a concussion play, active tackling, players on the punting team are more prone to concussions."}],"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}