{"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_minor":4,"nbformat":4,"cells":[{"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 20GB 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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-01-06T23:00:24.339722Z","iopub.execute_input":"2022-01-06T23:00:24.340126Z","iopub.status.idle":"2022-01-06T23:00:24.3518Z","shell.execute_reply.started":"2022-01-06T23:00:24.340091Z","shell.execute_reply":"2022-01-06T23:00:24.350687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load data","metadata":{}},{"cell_type":"code","source":"playersdf = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/players.csv')\nplaysdf = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/plays.csv')\nscoutdf = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/PFFScoutingData.csv')\ngamesdf = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/games.csv')\nt2018df = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/tracking2018.csv')\n#t2019df = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/tracking2019.csv')\n#t2020df = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/tracking2020.csv')","metadata":{"execution":{"iopub.status.busy":"2022-01-06T23:00:24.353412Z","iopub.execute_input":"2022-01-06T23:00:24.354186Z","iopub.status.idle":"2022-01-06T23:01:09.055265Z","shell.execute_reply.started":"2022-01-06T23:00:24.354151Z","shell.execute_reply":"2022-01-06T23:01:09.054232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Identify Successful Special Teams Plays\n* For Field Goals = Score a field goal\n* For Punts = Pin the opponent within their own 10 yard line\n* For Returns = Have a 40+ yard return","metadata":{}},{"cell_type":"code","source":"plays = playsdf.fillna(0)\nsuccessfulKick = plays.loc[(plays['specialTeamsPlayType'] == 'Field Goal') & (plays['specialTeamsResult'] == 'Kick Attempt Good')]\nsuccessfulKickBlock = plays.loc[(plays['specialTeamsPlayType'] == 'Field Goal') & (plays['specialTeamsResult'] == 'Blocked Kick Attempt')]\nsuccessfulPunts = plays.loc[(plays['specialTeamsPlayType'] == 'Punt') & (plays['possessionTeam'] == plays['yardlineSide']) & (plays['yardlineNumber'] + plays['kickLength'] == 99)]\nsuccessfulReturn = plays.loc[(plays['playDescription'].str.contains('TOUCHDOWN')) &(plays['specialTeamsResult'].str.contains('Non-Special Teams Result') == 0)&(plays['kickReturnYardage'] >= 1)]","metadata":{"execution":{"iopub.status.busy":"2022-01-06T23:01:09.05676Z","iopub.execute_input":"2022-01-06T23:01:09.057092Z","iopub.status.idle":"2022-01-06T23:01:09.152534Z","shell.execute_reply.started":"2022-01-06T23:01:09.05705Z","shell.execute_reply":"2022-01-06T23:01:09.151721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Mark Successful Plays in the Dataset","metadata":{}},{"cell_type":"code","source":"successplays = pd.concat([successfulKick,successfulKickBlock,successfulPunts,successfulReturn])\nplays['Success'] = [1 if x in successplays['playId'] else 0 for x in plays['playId']]\ndisplay(plays)","metadata":{"execution":{"iopub.status.busy":"2022-01-06T23:16:53.049915Z","iopub.execute_input":"2022-01-06T23:16:53.050283Z","iopub.status.idle":"2022-01-06T23:16:53.289638Z","shell.execute_reply.started":"2022-01-06T23:16:53.050248Z","shell.execute_reply":"2022-01-06T23:16:53.288559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Encode Other Data","metadata":{}},{"cell_type":"code","source":"playsencoded = pd.get_dummies(plays, columns=['possessionTeam','specialTeamsPlayType','specialTeamsResult','down','quarter'])\ndisplay(playsencoded)\n","metadata":{"execution":{"iopub.status.busy":"2022-01-06T23:21:22.000525Z","iopub.execute_input":"2022-01-06T23:21:22.000881Z","iopub.status.idle":"2022-01-06T23:21:22.058349Z","shell.execute_reply.started":"2022-01-06T23:21:22.000836Z","shell.execute_reply":"2022-01-06T23:21:22.057476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Find Correlation Between Successful Plays and Other Data\n","metadata":{}},{"cell_type":"code","source":"successCorr = playsencoded.corrwith(playsencoded['Success'])","metadata":{"execution":{"iopub.status.busy":"2022-01-06T23:21:26.739951Z","iopub.execute_input":"2022-01-06T23:21:26.740285Z","iopub.status.idle":"2022-01-06T23:21:26.787089Z","shell.execute_reply.started":"2022-01-06T23:21:26.740247Z","shell.execute_reply":"2022-01-06T23:21:26.786141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**","metadata":{}},{"cell_type":"code","source":"display(successCorr.sort_values().tail(30))","metadata":{"execution":{"iopub.status.busy":"2022-01-06T23:21:31.275218Z","iopub.execute_input":"2022-01-06T23:21:31.275549Z","iopub.status.idle":"2022-01-06T23:21:31.283645Z","shell.execute_reply.started":"2022-01-06T23:21:31.275512Z","shell.execute_reply":"2022-01-06T23:21:31.283082Z"},"trusted":true},"execution_count":null,"outputs":[]}]}