{"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 all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\n\nfrom IPython.core.interactiveshell import InteractiveShell\nInteractiveShell.ast_node_interactivity = \"all\"\n%config InlineBackend.figure_format ='retina'\n%matplotlib inline","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"injury = pd.read_csv('/kaggle/input/nfl-playing-surface-analytics/InjuryRecord.csv')\nplaylist = pd.read_csv('/kaggle/input/nfl-playing-surface-analytics/PlayList.csv')\n#playertrack = pd.read_csv('/kaggle/input/nfl-playing-surface-analytics/PlayerTrackData.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"injury.info()\nplaylist.info()\n#playertrack.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"injury.sort_values(by='PlayerKey')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# check for nan\ninjury.isnull().sum()\nplaylist.isnull().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"injury['PlayerKey'].nunique()#.head().sort_values(by='PlayerKey')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"injury.head()\ninjury['BodyPart'].unique()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"injury.Surface.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.countplot(injury[\"Surface\"])\nplt.box(False)\nplt.title('Injury Distribution Surfaces')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#injury['BodyPart'].value_counts().plot(kind='bar')\n\nsns.countplot(injury[\"BodyPart\"])\nplt.box(False)\nplt.title('Distribution Body Parts Injured')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"injury.BodyPart.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"order = injury['Surface'].value_counts(ascending=True).index\nsns.countplot(x='Surface', hue = 'BodyPart', data=injury, order = order)\nplt.box(False)\nplt.title(\"Injuries in Body Part by Surface Type\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"injury.head()\ninjury.isnull().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"injury.apply(pd.Series.value_counts)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"injury.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"injury.DM_M1.value_counts()\ninjury.DM_M7.value_counts()\ninjury.DM_M28.value_counts()\ninjury.DM_M42.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# undummy time missing after injuries\ninjury.loc[(injury['DM_M1'] + injury['DM_M7'] + injury['DM_M28'] + injury['DM_M42'] == 4), 'Time_missing'] = '42+ days'\ninjury.loc[(injury['DM_M1'] + injury['DM_M7'] + injury['DM_M28'] + injury['DM_M42'] == 3), 'Time_missing'] = '28+ days'\ninjury.loc[(injury['DM_M1'] + injury['DM_M7'] + injury['DM_M28'] + injury['DM_M42'] == 2), 'Time_missing'] = '7+ days'\ninjury.loc[(injury['DM_M1'] + injury['DM_M7'] + injury['DM_M28'] + injury['DM_M42'] == 1), 'Time_missing'] = '1+ days'\n\ninjury.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#visualize time missing\nplt.figure(figsize=(10,6))\nsns.countplot(x='Time_missing', hue = 'BodyPart', data=injury, order = ['42+ days','28+ days','7+ days','1+ days'])#palette=\"Set3\"\nplt.box(False)\nplt.title(\"\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#visualize time missing\nplt.figure(figsize=(10,6))\nsns.countplot(x='BodyPart', hue = 'Time_missing', data=injury, order = ['Knee','Ankle','Foot','Toes','Heel'],palette=\"nipy_spectral_r\")\nplt.box(False)\nplt.legend(loc='upper right')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=(10,7))\norder3 = injury['Surface'].value_counts(ascending=True).index\nsns.countplot(x='Surface', hue = 'Time_missing', data=injury, order = order3, palette=\"Set3\")\nplt.box(False)\nplt.legend(loc='upper right')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Statistical Test on whether significant\n#chi-square?","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"playlist['PlayerKey'].nunique()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"comb = pd.merge(playlist, injury, on='PlayerKey', how='outer')\ncomb.head(10)\ncomb.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\ncomb['BodyPart'] = comb.BodyPart.fillna('noInjury')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"comb.BodyPart.unique()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"comb.Surface.value_counts()\ncomb.Surface.isnull().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"comb[comb['GameID_x'] == '26624-1']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"comb[['DM_M1','DM_M7','DM_M28','DM_M42']] = comb[['DM_M1','DM_M7','DM_M28','DM_M42']].fillna(0)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"comb = comb.drop(['GameID_y','PlayKey_y','Surface'], axis=1)\ncomb","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"comb.loc[(comb['DM_M1'] + comb['DM_M7'] + comb['DM_M28'] + comb['DM_M42'] == 0), 'Time_missing'] = 'none'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"comb.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#visualize Position and Injury\nplt.figure(figsize=(18,6))\nsns.countplot(x='RosterPosition', hue = 'BodyPart', data=comb, palette=\"nipy_spectral_r\")\nplt.box(False)\nplt.legend(loc='upper right')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=(20,6))\nsns.countplot(comb.StadiumType)\nplt.box(False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=(20,6))\nsns.countplot(comb.FieldType)\nplt.box(False)\n\ncomb.FieldType.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#visualize FieldType and Injury\nplt.figure(figsize=(18,6))\nsns.countplot(x='FieldType', hue = 'BodyPart', data=comb, palette=\"nipy_spectral_r\")\nplt.box(False)\nplt.legend(loc='upper right')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#visualize FieldType and Injury\n\n#comb['Perc_FieldType']= comb.FieldType.value_counts('Synthetic')/comb.FieldType.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"comb.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","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}