{"cells":[{"metadata":{},"cell_type":"markdown","source":"### NFL 1st AND FUTURE ANALYTICS - 2019"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"_kg_hide-input":false},"cell_type":"code","source":"import os\nimport warnings\n%matplotlib inline\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport plotly.express as px\nimport matplotlib.pyplot as plt\nimport chart_studio.plotly as py\nwarnings.filterwarnings(\"ignore\")\nimport plotly.graph_objects as go\nfrom plotly.subplots import make_subplots","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"playlist = pd.read_csv('../input/nfl-playing-surface-analytics/PlayList.csv')\ninjuries = pd.read_csv('../input/nfl-playing-surface-analytics/InjuryRecord.csv')\ntracking = pd.read_csv('../input/nfl-playing-surface-analytics/PlayerTrackData.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(\"Playlist \", playlist.shape)\nprint(\"Injury Record \", injuries.shape)\nprint(\"Player Track Data \", tracking.shape)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(playlist.columns)\nprint(injuries.columns)\nprint(tracking.columns)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"*Playkey is the common column*"},{"metadata":{},"cell_type":"markdown","source":"## Playlist"},{"metadata":{"trusted":true},"cell_type":"code","source":"playlist.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"playlist.isnull().any().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"playlist.dtypes","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"len(np.unique(playlist['PlayKey']))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Number of Unique Games Played = 267006**"},{"metadata":{"trusted":true},"cell_type":"code","source":"x = playlist['StadiumType'].value_counts().index\ny = playlist['StadiumType'].value_counts().values\nfig = go.Figure(data=[go.Bar(x=x, y=y,text=y,textposition='auto',marker={'color': 'royalblue'})])\nfig.update_xaxes(tickangle=45);fig.update_layout( title={'text': \"Stadium Distribution\",'y':0.9,'x':0.5,'xanchor': 'center','yanchor': 'top'},xaxis_title=\"Stadium Types\",yaxis_title=\"Number of Games Played\",font=dict(family=\"Courier New, monospace\",size=18,color=\"#7f7f7f\"))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"x = playlist[playlist['Temperature'] != -999]['Temperature'].value_counts().index\ny = playlist[playlist['Temperature'] != -999]['Temperature'].value_counts().values\nfig = go.Figure(data=[go.Bar(x=x, y=y,text=y,textposition='auto',marker={'color': 'royalblue'})])\nfig.update_xaxes(tickangle=45);fig.update_layout( title={'text': \"Temprature Distribution\",'y':0.9,'x':0.5,'xanchor': 'center','yanchor': 'top'},xaxis_title=\"Temperature (in F)\",yaxis_title=\"Number of Games Played\",font=dict(family=\"Courier New, monospace\",size=18,color=\"#7f7f7f\"))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Seems that in most of the matches, temprature was not recorded. Hence, it is entered as -999.**"},{"metadata":{"trusted":true},"cell_type":"code","source":"frame = { 'Index': playlist[['PlayKey', 'PlayType']].groupby('PlayType').count().sort_values(by='PlayType').index, 'Values': playlist[['PlayKey', 'PlayType']].groupby('PlayType').count()['PlayKey'].values} \nresult = pd.DataFrame(frame) \n\nfig = px.bar(result, x=\"Index\", y=\"Values\", title=\"Play Type Matches\", labels={'Index': 'Types of Play', 'Values': 'Number of Matches'})\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"frame = { 'Index': playlist['FieldType'].value_counts().index, 'Values': playlist['FieldType'].value_counts().values} \nresult = pd.DataFrame(frame) \n\nfig = px.bar(result, x=\"Index\", y=\"Values\", title=\"Play Type Matches\", labels={'Index': 'Turf Type', 'Values': 'Number of Matches'})\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Injuries"},{"metadata":{"trusted":true},"cell_type":"code","source":"injuries.dtypes","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"injuries.head(3)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = make_subplots(rows=1, cols=2)\nx1 = playlist[['FieldType', 'PlayKey']].drop_duplicates().groupby('FieldType').count().index.values\ny1 = playlist[['FieldType', 'PlayKey']].drop_duplicates().groupby('FieldType').count()['PlayKey'].values\nx2 = injuries[['Surface', 'PlayKey']].drop_duplicates().groupby('Surface').count().index.values\ny2 = injuries[['Surface', 'PlayKey']].drop_duplicates().groupby('Surface').count()['PlayKey'].values\n# fig.show()\nfig.add_trace(\n    go.Bar(x=x1, y=y1, name=\"Turf Wise Games \"),\n    row=1, col=1,\n)\nfig.add_trace(\n    go.Bar(x=x2, y=y2, name=\"Turf Wise Injuries\"),\n    row=1, col=2\n)\nfig.update_layout(height=600, width=800, title_text=\"Plays/Injuries\")\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":""},{"metadata":{},"cell_type":"markdown","source":"### More Injuries are observed on Synthetic Turf even though more number of matches were played on Natural Turf"},{"metadata":{"trusted":true},"cell_type":"code","source":"df = pd.merge(injuries, playlist, on=\"PlayKey\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df['StadiumType'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### More Coming Soon!"}],"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}