{"cells":[{"metadata":{},"cell_type":"markdown","source":"**NFL 1st and Future - Analytics**\n\nFocus on the specifics : Challenge is to characterize any differences in player movement between the playing surfaces and identify specific scenarios (e.g., field surface, weather, position, play type, etc.) that interact with player movement to present an elevated risk of injury."},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"import numpy as np\nfrom matplotlib import pyplot as plt\nimport pandas as pd\nimport seaborn as sb\n\nfrom pylab import rcParams\nrcParams['figure.figsize'] = 50, 10","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"","_uuid":"","trusted":true},"cell_type":"code","source":"\nnfl_pl = pd.read_csv(\"../input/nfl-playing-surface-analytics/PlayList.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"nfl_pl['StadiumType']=nfl_pl['StadiumType'].replace(to_replace =['Outdoors', 'Outddors', 'Oudoors','Oudoor', 'Ourdoor', 'Outdor', 'Outside', 'Cloudy', 'Outdoor Retr Roof-Open','Indoors','Indoor', 'Indoor, Open Roof', 'Indoor, Roof Closed'], \n                            value =[\"Outdoor\", \"Outdoor\", \"Outdoor\",\"Outdoor\", \"Outdoor\", \"Outdoor\", \"Outdoor\", \"Outdoor\",\"Outdoor\", \"Indoor\", \"Indoor\", \"Indoor\", \"Indoor\"])\n\nnfl_pl['StadiumType']=nfl_pl['StadiumType'].replace(to_replace =['Dome', 'Dome, closed', 'Domed', 'Domed, Open', 'Domed, closed', 'Domed, open', 'Closed Dome'], \n                            value =[\"Dome\", \"Dome\",\"Dome\",\"Dome\",\"Dome\",\"Dome\",\"Dome\"])\n\nnfl_pl['StadiumType']=nfl_pl['StadiumType'].replace(to_replace =['Retractable Roof', 'Retr. Roof - Closed', 'Retr. Roof - Open', 'Retr. Roof Closed', 'Retr. Roof-Closed', 'Retr. Roof-Open'], \n                            value =[\"Retractable Roof\", \"Retractable Roof\",\"Retractable Roof\",\"Retractable Roof\",\"Retractable Roof\",\"Retractable Roof\",])\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"del nfl_pl['Position'],nfl_pl['PositionGroup'],nfl_pl['Temperature']\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Merging datasets"},{"metadata":{"trusted":true},"cell_type":"code","source":"nfl_ir = pd.read_csv(\"../input/nfl-playing-surface-analytics/InjuryRecord.csv\")\ndf_m_ir_pl = pd.merge(nfl_pl, nfl_ir, on = ['PlayerKey','GameID','PlayKey'], how='inner')\nprint (df_m_ir_pl.shape)\nprint (df_m_ir_pl.columns)\nprint (df_m_ir_pl.groupby('RosterPosition').size())","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"raw","source":"Merging Player Track Data"},{"metadata":{"trusted":true},"cell_type":"code","source":"nfl_ptd = pd.read_csv(\"../input/nfl-playing-surface-analytics/PlayerTrackData.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\ndf_m_ptd_2mrg = pd.merge(df_m_ir_pl, nfl_ptd, on = 'PlayKey')\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"nfl_final_1 = df_m_ptd_2mrg\nprint (nfl_final_1.shape)\nnfl_final_1 = nfl_final_1.dropna()\nprint (nfl_final_1.shape)\nnfl_final_1.rename(columns = {'s':'Speed', 'o':'Orientation'}) \n\nprint(nfl_final_1.columns)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"nfl_final = nfl_final_1\nprint(nfl_final.columns)\n\nprint ('FacetGrid to characterize any differences in player movement between the playing surfaces with - plot for further tweaking')\nsb.relplot(x='x',y='y',hue='Surface',size='RosterPosition',col='PlayType',row='event',height=5, data=nfl_final)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print ('FacetGrid identify specific scenarios like weather, position etc. that interact with player movement to present an elevated risk of injury - with plot for further tweaking')\nsb.relplot(x='x',y='y',hue='BodyPart',size='Weather',col='RosterPosition',row='PlayType',height=5, data=nfl_final)","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":1}