{"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\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 read-only \"../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# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport os\nimport matplotlib.pylab as plt\nimport seaborn as sns\nimport matplotlib.patches as patches\nsns.set_style(\"whitegrid\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"InjuryRecord_Data = pd.read_csv(\"/kaggle/input/nfl-playing-surface-analytics/InjuryRecord.csv\", sep= \",\" ) \nPlayerTrackData_Data = pd.read_csv(\"/kaggle/input/nfl-playing-surface-analytics/PlayerTrackData.csv\", sep= \",\" ) \nPlayList_Data = pd.read_csv(\"/kaggle/input/nfl-playing-surface-analytics/PlayList.csv\", sep= \",\" ) ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(\"shape of Injury record is:\" , InjuryRecord_Data.shape)\nprint(\"shape of Player trackdata is:\" ,PlayerTrackData_Data.shape)\nprint(\"shape of PlayList is:\" , PlayList_Data.shape)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"InjuryRecord_Data.head(10)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"PlayerTrackData_Data.head(10)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# InjuryRecord Data","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"InjuryRecord_Data.isnull().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"InjuryRecord_Data.groupby(['BodyPart']).count()['PlayerKey'].sort_values().plot(kind=\"bar\", figsize=(15, 5), title='Count of injuries by Body Part')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"InjuryRecord_Data.groupby(['Surface']).count()['PlayerKey'].sort_values().plot(kind=\"bar\", figsize=(15, 5), title='Count of injuries by Surface')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"InjuryRecord_Data.groupby(['Surface','BodyPart']).count()['PlayerKey'].sort_values().plot(kind=\"bar\", figsize=(15, 5), title='Count of injuries by Surface and BodyPart')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"InjuryRecord_Data.groupby(['BodyPart','Surface']).count().unstack('BodyPart')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"InjuryRecord_Data.groupby(['BodyPart','Surface']).count().unstack('BodyPart')['PlayerKey'].sort_values('Surface').plot(kind= \"bar\" ,figsize=(15, 5), title='Count of injuries by Surface')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"On \"natural\" turf, max. injuries occured on knees whereas max injuries on \"synthetic\" surface happened on Ankle.\nsynthetic suface shows no injury on Player heels","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"#lets check, is there any player who had multiple injuries:\nInjuryRecord_Data[InjuryRecord_Data.duplicated(['PlayerKey'])]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"InjuryRecord_Data.groupby(['Surface','BodyPart','PlayerKey']).count().unstack('BodyPart')['GameID'].sort_values('PlayerKey').plot(kind= \"bar\" ,figsize=(15, 5), title='Count of player injuries ')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Player 43450 had Ankle injury twice on Synthetic Surface, whereas none other player got same injury on same surface more than once.","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"InjuryRecord_Data.groupby(['BodyPart','PlayerKey']).count().unstack('BodyPart')['GameID'].sort_values('PlayerKey').plot(kind= \"bar\" ,figsize=(15, 5), title='Count of player injuries ')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Player 33337(on foot) and 43540(on Ankle) got injuries twice on same body part","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"InjuryRecord_Data.groupby(['PlayerKey']).count().sort_values('PlayerKey').plot(kind= \"bar\" ,figsize=(15, 5), title='Count of player injuries ')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# # PlayList data","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"PlayList_Data.isnull().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"PlayList_Data.RosterPosition.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"PlayList_Data.StadiumType.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"PlayList_Data.Weather.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"PlayList_Data.PlayType.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"PlayList_Data.FieldType.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"PlayList_Data.PlayerGamePlay.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"PlayList_Data[['PlayKey','PlayType']].drop_duplicates() \\\n    .groupby('PlayType').count()['PlayKey'] \\\n    .sort_values() \\\n    .plot(kind='barh',\n         figsize=(15, 6),\n          color='Teal',\n         title='Number of plays provided by type')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"PlayList_Data[['PlayKey','RosterPosition']].drop_duplicates() \\\n    .groupby('RosterPosition').count()['PlayKey'] \\\n    .sort_values() \\\n    .plot(kind='barh',\n         figsize=(15, 6),\n          color='olive',\n         title='Number of plays provided by player position')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"inj_detailed = InjuryRecord_Data.merge(PlayList_Data, on = [\"PlayerKey\",\"GameID\",\"PlayKey\"] , how=\"left\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"inj_detailed.head(5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"inj_detailedd = inj_detailed.drop(['FieldType'],axis=1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#lets plt 105 players injuries w.r.t bodyparts\ninj_detailed.groupby(['PlayerKey','BodyPart']).count().unstack('BodyPart')['GameID'].sort_values('PlayerKey').sort_values('Ankle').sort_values('Knee').plot(kind= \"bar\" ,figsize=(15, 8), title='Count of player injuries ')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"inj_detailed.groupby([\"Surface\",\"RosterPosition\",\"BodyPart\"]).count()['PlayerKey'].unstack(\"Surface\").sort_values('RosterPosition').plot(kind= \"bar\" ,figsize=(15, 5), title='Players Injured in their respective Play positions on different Surfaces...')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"inj_detailed.groupby([\"RosterPosition\",\"BodyPart\"]).count()['PlayerKey'].unstack('BodyPart').sort_values('Ankle').plot(kind= \"bar\", figsize=(15, 5), title='Players BodyPart injuries in their respective Play positions ')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"inj_detailed.groupby([\"PlayType\",\"Surface\"]).count()['PlayerKey'].unstack('Surface').plot(kind= \"bar\", figsize=(15, 5), title='Players Injured in their respective Play positions on different Surfaces...')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"inj_detailed.groupby([\"Surface\",\"PlayType\",\"BodyPart\"]).count()['PlayerKey'].unstack(\"BodyPart\").sort_values('Surface', ascending=False).plot(kind= \"bar\" ,figsize=(15, 5), title=\"Players Injured BodyParts in respective plays type on different turf\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","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":4}