{"cells":[{"metadata":{"_uuid":"ff450a8145870b7f7b1a3b863ce088af582384b8"},"cell_type":"markdown","source":"# Watch the Videos Showing Injury\n\nFor manual viewing (with eyes) it's easiest to see collisions causing injury by looking for the jersey numbers in the videos.\n\nThis notebook's output generates a table catered to simple display with minimal distraction data for manual viewing."},{"metadata":{"trusted":true,"_uuid":"3aa9cfe8894a6004cb9a209737a2fcd22240cb3b"},"cell_type":"code","source":"import pandas as pd\nimport numpy as np\n\nplayer_info = pd.read_csv('../input/player_punt_data.csv')\nplayer_info.head()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"f8eacb6caa834ba82de49d4ffcb306253a07e6c8"},"cell_type":"markdown","source":"Unfortunately, this data set has 637 players that have multiple numbers or positions."},{"metadata":{"trusted":true,"_uuid":"c7f8364bcb2b74dd3ec291bfaca428e4bf32fa64"},"cell_type":"code","source":"grouped = player_info.groupby('GSISID').agg('count')\ngrouped[(grouped.Number > 1) | (grouped.Position > 1)].count()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"a197a5af88545078d346c3e59d5a60a8ad7d3251"},"cell_type":"markdown","source":"The data provided doesn't specify the play ID or game ID for each GSISID, so group the numbers and positions by GSISID (player ID) so we can look for all the jersey numbers each player might be wearing in each video.  The letters 'o' and 'd' are included in jersey numbers as well, so remove letters since a real jersey number cannot actually include a letter."},{"metadata":{"trusted":true,"_uuid":"5838b3d410103a1e8a4b42963d9e9192ccee4568"},"cell_type":"code","source":"grouped_player_info = player_info.groupby('GSISID').agg({\n    'Number': lambda x: ','.join(x.replace(to_replace='[^0-9]', value='', regex=True).unique()), \n    'Position': lambda x: ','.join(x.unique())})\n\ngrouped_player_info.head(50)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"3e628430a8c4a52f9dd64bef2235194e6424aaf0"},"cell_type":"markdown","source":"Now, produce a combined table with the jersey number and position information that might be useful later with the play and NGS information."},{"metadata":{"trusted":true,"_uuid":"1dff368fc64b8a9e73281f03fe9462e9f1e08759"},"cell_type":"code","source":"video_review = pd.read_csv('../input/video_review.csv', na_values='Unclear', dtype={'Primary_Partner_GSISID': np.float64}) \nvideo_footage_injury = pd.read_csv('../input/video_footage-injury.csv')\n\nvideos = pd.merge(video_review, video_footage_injury, left_on=['PlayID','GameKey'], right_on=['playid','gamekey'])\nvideos = pd.merge(videos, grouped_player_info, how='left', left_on='GSISID', right_on='GSISID')\nvideos.rename({'Number': 'Injured Player Number(s)', 'Position': 'Injured Player Position'}, axis=1, inplace=True)\nvideos = pd.merge(videos, grouped_player_info, how='left', left_on='Primary_Partner_GSISID', right_on='GSISID')\nvideos.rename({'Number': 'Other Player Number(s)', 'Position': 'Other Player Position'}, axis=1, inplace=True)\n# Remove duplicate columns\nvideos.drop(['gamekey', 'playid', 'season'], axis=1, inplace=True)\npd.set_option(\"display.max_columns\", 50)\npd.set_option('display.max_colwidth', 30)\nvideos.head()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"a363aea3e3059fa453e4ee55aef9d908130e4315"},"cell_type":"markdown","source":"# Watch the video"},{"metadata":{"_kg_hide-input":false,"trusted":true,"_uuid":"c40322ff953ec5eff720623bdd3ccf5539bb85af"},"cell_type":"code","source":"from IPython.display import HTML\n# Remove some columns that distract in manual viewing\nwatch = videos.drop(['GameKey', 'PlayID', 'GSISID', 'Season_Year', 'Primary_Partner_GSISID', 'Type', 'Week', 'Qtr', 'PlayDescription', 'Home_team', 'Visit_Team'], axis=1)\nwatch.rename({'Player_Activity_Derived': 'Injured Player Action', 'Primary_Partner_Activity_Derived': 'Other Player Action', 'Turnover_Related': 'From Turnover', 'Friendly_Fire': 'Friendly Fire'}, axis=1, inplace=True)\nwatch['PREVIEW LINK (5000K)'] = watch['PREVIEW LINK (5000K)'].apply(lambda x: '<a href=\"{0}\" target=\"__blank\">video link</a>'.format(x))\npd.set_option('display.max_colwidth', -1)\nHTML(watch.to_html(escape=False))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"bba7a2e07715374a91af3e204935c7f44c5ecc87"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.0"}},"nbformat":4,"nbformat_minor":1}