{"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":"2021-09-25T06:36:04.540321Z","iopub.execute_input":"2021-09-25T06:36:04.541301Z","iopub.status.idle":"2021-09-25T06:36:04.567313Z","shell.execute_reply.started":"2021-09-25T06:36:04.541157Z","shell.execute_reply":"2021-09-25T06:36:04.566649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"1. Game Data\nGame data: The games.csv contains the teams playing in each game. The key variable is gameId.\ngameId: Game identifier, unique (numeric)\n\ngameDate: Game Date (time, mm/dd/yyyy)\n\ngameTimeEastern: Start time of game (time, HH:MM:SS, EST)\n\nhomeTeamAbbr: Home team three-letter code (text)\n\nvisitorTeamAbbr: Visiting team three-letter code (text","metadata":{}},{"cell_type":"code","source":"import pandas as pd","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:37:37.204961Z","iopub.execute_input":"2021-09-25T06:37:37.205284Z","iopub.status.idle":"2021-09-25T06:37:37.209794Z","shell.execute_reply.started":"2021-09-25T06:37:37.205234Z","shell.execute_reply":"2021-09-25T06:37:37.208867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games=pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/games.csv')","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:38:11.610709Z","iopub.execute_input":"2021-09-25T06:38:11.611407Z","iopub.status.idle":"2021-09-25T06:38:11.649368Z","shell.execute_reply.started":"2021-09-25T06:38:11.611369Z","shell.execute_reply":"2021-09-25T06:38:11.648621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:38:15.185185Z","iopub.execute_input":"2021-09-25T06:38:15.186005Z","iopub.status.idle":"2021-09-25T06:38:15.213149Z","shell.execute_reply.started":"2021-09-25T06:38:15.185968Z","shell.execute_reply":"2021-09-25T06:38:15.212373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.express as px\ncheck = games['gameDate'].value_counts().reset_index()\n\ncheck.columns = [\n    'date', \n    'games'\n]\n\ncheck = check.sort_values('games')\n\nfig = px.bar(\n    check, \n    y='date', \n    x=\"games\", \n    orientation='h', \n    title='Number of games for every date', \n    height=900, \n    width=800\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:42:28.505877Z","iopub.execute_input":"2021-09-25T06:42:28.50618Z","iopub.status.idle":"2021-09-25T06:42:31.272183Z","shell.execute_reply.started":"2021-09-25T06:42:28.506151Z","shell.execute_reply":"2021-09-25T06:42:31.271395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = games['gameTimeEastern'].value_counts().reset_index()\n\ncheck.columns = [\n    'time', \n    'games'\n]\n\ncheck = check.sort_values('games')\n\nfig = px.bar(\n    check, \n    y='time', \n    x=\"games\", \n    orientation='h', \n    title='Number of games for every time', \n    height=400, \n    width=800\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:43:11.865983Z","iopub.execute_input":"2021-09-25T06:43:11.866383Z","iopub.status.idle":"2021-09-25T06:43:11.93465Z","shell.execute_reply.started":"2021-09-25T06:43:11.866354Z","shell.execute_reply":"2021-09-25T06:43:11.933899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = games['homeTeamAbbr'].value_counts().reset_index()\n\ncheck.columns = [\n    'team', \n    'games'\n]\n\ncheck = check.sort_values('games')\n\nfig = px.bar(\n    check, \n    y='team', \n    x=\"games\", \n    orientation='h', \n    title='Number of games for every team (home)', \n    height=700, \n    width=800\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:43:46.365906Z","iopub.execute_input":"2021-09-25T06:43:46.366343Z","iopub.status.idle":"2021-09-25T06:43:46.432823Z","shell.execute_reply.started":"2021-09-25T06:43:46.366312Z","shell.execute_reply":"2021-09-25T06:43:46.432295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = games['visitorTeamAbbr'].value_counts().reset_index()\n\ncheck.columns = [\n    'team', \n    'games'\n]\n\ncheck = check.sort_values('games')\n\nfig = px.bar(\n    check, \n    y='team', \n    x=\"games\", \n    orientation='h', \n    title='Number of games for every team (away)', \n    height=700, \n    width=800\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:44:18.376006Z","iopub.execute_input":"2021-09-25T06:44:18.376435Z","iopub.status.idle":"2021-09-25T06:44:18.443669Z","shell.execute_reply.started":"2021-09-25T06:44:18.376406Z","shell.execute_reply":"2021-09-25T06:44:18.443135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = games['week'].value_counts().reset_index()\n\ncheck.columns = [\n    'week', \n    'games'\n]\n\ncheck = check.sort_values('games')\ncheck['week'] = check['week'].astype(str) + '-'\n\nfig = px.bar(\n    check, \n    y='week', \n    x=\"games\", \n    orientation='h', \n    title='Number of games for every week', \n    height=500, \n    width=800\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:44:54.075732Z","iopub.execute_input":"2021-09-25T06:44:54.076014Z","iopub.status.idle":"2021-09-25T06:44:54.147935Z","shell.execute_reply.started":"2021-09-25T06:44:54.075983Z","shell.execute_reply":"2021-09-25T06:44:54.147112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"2. Player Data\nPlayer data: The players.csv file contains player-level information from players that participated in any of the tracking data files. The key variable is nflId\nnflId: Player identification number, unique across players (numeric)\n\nheight: Player height (text)\n\nweight: Player weight (numeric)\n\nbirthDate: Date of birth (YYYY-MM-DD)\n\ncollegeName: Player college (text)\n\nposition: Player position (text)\n\ndisplayName: Player name (text)","metadata":{}},{"cell_type":"code","source":"players=pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/players.csv')","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:47:23.778236Z","iopub.execute_input":"2021-09-25T06:47:23.778599Z","iopub.status.idle":"2021-09-25T06:47:23.791481Z","shell.execute_reply.started":"2021-09-25T06:47:23.778566Z","shell.execute_reply":"2021-09-25T06:47:23.790208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:47:28.114782Z","iopub.execute_input":"2021-09-25T06:47:28.115041Z","iopub.status.idle":"2021-09-25T06:47:28.13481Z","shell.execute_reply.started":"2021-09-25T06:47:28.115013Z","shell.execute_reply":"2021-09-25T06:47:28.133881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = players['height'].str.split('-',expand=True)\n\ncheck.columns = [\n    'first', \n    'second'\n]\n\ncheck.loc[(check['second'].notnull()), 'first'] = check[check['second'].notnull()]['first'].astype(np.int16) * 12 + check[check['second'].notnull()]['second'].astype(np.int16)","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:47:51.086042Z","iopub.execute_input":"2021-09-25T06:47:51.08634Z","iopub.status.idle":"2021-09-25T06:47:51.106988Z","shell.execute_reply.started":"2021-09-25T06:47:51.086309Z","shell.execute_reply":"2021-09-25T06:47:51.10628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players['height'] = check['first']\nplayers['height'] = players['height'].astype(np.float32)\nplayers['height'] /= 12\n\nplayers","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:48:11.94559Z","iopub.execute_input":"2021-09-25T06:48:11.945899Z","iopub.status.idle":"2021-09-25T06:48:11.9691Z","shell.execute_reply.started":"2021-09-25T06:48:11.945868Z","shell.execute_reply":"2021-09-25T06:48:11.96829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players.head()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:48:27.155657Z","iopub.execute_input":"2021-09-25T06:48:27.155954Z","iopub.status.idle":"2021-09-25T06:48:27.169933Z","shell.execute_reply.started":"2021-09-25T06:48:27.155922Z","shell.execute_reply":"2021-09-25T06:48:27.168994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from plotly.subplots import make_subplots\nimport plotly.graph_objects as go\nfig = make_subplots(rows=1, cols=2)\ntraces = [\n    go.Histogram(\n        x=players[col[0]], \n        nbinsx=col[1], \n        name=col[0]\n    ) for col in [('height', 20), ('weight', 50)]\n]\n\nfor i in range(len(traces)):\n    fig.append_trace(\n        traces[i], \n        (i // 2) + 1, \n        (i % 2) + 1\n    )\n\nfig.update_layout(\n    title_text='Height & weight distributions',\n    height=400,\n    width=800\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:53:20.746944Z","iopub.execute_input":"2021-09-25T06:53:20.747202Z","iopub.status.idle":"2021-09-25T06:53:20.795118Z","shell.execute_reply.started":"2021-09-25T06:53:20.747176Z","shell.execute_reply":"2021-09-25T06:53:20.794219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = players['collegeName'].value_counts().reset_index()\n\ncheck.columns = [\n    'college', \n    'players'\n]\n\ncheck = check.sort_values('players').tail(50)\n\nfig = px.bar(\n    check, \n    y='college', \n    x=\"players\", \n    orientation='h', \n    title='Top 50 colleges by number of players',\n    height=900,\n    width=800\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:53:49.985841Z","iopub.execute_input":"2021-09-25T06:53:49.986356Z","iopub.status.idle":"2021-09-25T06:53:50.057919Z","shell.execute_reply.started":"2021-09-25T06:53:49.986319Z","shell.execute_reply":"2021-09-25T06:53:50.057041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Players positions abbreviation\nWR: Wide Receiver;\nCB: Cornerback;\nRB: Running Back;\nTE: Tight End;\nOLB: Outside Linebacker;\nQB: Quarterback;\nFS: Free Safety;\nLB: Linebacker;\nSS: Strong Safety;\nILB: Inside Linebacker;\nDE: Defensive End;\nDB: Defensive Back;\nMLB: Middle Linebacker;\nDT: Defensive Tackle;\nFB: Fullback;\nP: Punter;\nLS: Long snapper;\nS: Safety;\nK: Kicker;\nHB: Running back;\nNT: Nose Tackle","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"3. Play Data\nPlay data: The plays.csv file contains play-level information from each game. The key variables are gameId and playId\ngameId: Game identifier, unique (numeric)\n\nplayId: Play identifier, not unique across games (numeric)\n\nplayDescription: Description of play (text)\n\nquarter: Game quarter (numeric)\n\ndown: Down (numeric)\n\nyardsToGo: Distance needed for a first down (numeric)\n\npossessionTeam: Team on offense (text)\n\nplayType: Outcome of dropback: sack or pass (text)\n\nyardlineSide: 3-letter team code corresponding to line-of-scrimmage (text)\nyardlineNumber: Yard line at line-of-scrimmage (numeric)\n\noffenseFormation: Formation used by possession team (text)\n\npersonnelO: Personnel used by offensive team (text)\n\ndefendersInTheBox: Number of defenders in close proximity to line-of-scrimmage (numeric)\n\nnumberOfPassRushers: Number of pass rushers (numeric)\n\npersonnelD: Personnel used by defensive team (text)\n\ntypeDropback: Dropback categorization of quarterback (text)\n\npreSnapHomeScore: Home score prior to the play (numeric)\n\npreSnapVisitorScore: Visiting team score prior to the play (numeric)\n\ngameClock: Time on clock of play (MM:SS)\n\nabsoluteYardlineNumber: Distance from end zone for possession team (numeric)\n\npenaltyCodes: NFL categorization of the penalties that ocurred on the play. For purposes of this contest, the most important penalties are Defensive Pass Interference\n(DPI), Offensive Pass Interference (OPI), Illegal Contact (ICT), and Defensive Holding (DH). Multiple penalties on a play are separated by a ; (text)\n\npenaltyJerseyNumber: Jersey number and team code of the player commiting each penalty. Multiple penalties on a play are separated by a ; (text)\n\npassResult: Outcome of the passing play (C: Complete pass, I: Incomplete pass, S: Quarterback sack, IN: Intercepted pass, text)\n\noffensePlayResult: Yards gained by the offense, excluding penalty yardage (numeric)\n\nplayResult: Net yards gained by the offense, including penalty yardage (numeric)\n\nepa: Expected points added on the play, relative to the offensive team. Expected points is a metric that estimates the average of every next scoring outcome given the play's down, distance, yardline, and time remaining (numeric)\n\nisDefensivePI: An indicator variable for whether or not a DPI penalty ocurred on a given play (TRUE/FALSE)","metadata":{}},{"cell_type":"code","source":"plays=pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/plays.csv')","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:57:55.085291Z","iopub.execute_input":"2021-09-25T06:57:55.0856Z","iopub.status.idle":"2021-09-25T06:57:55.234914Z","shell.execute_reply.started":"2021-09-25T06:57:55.085568Z","shell.execute_reply":"2021-09-25T06:57:55.234118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plays","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:57:58.265116Z","iopub.execute_input":"2021-09-25T06:57:58.265803Z","iopub.status.idle":"2021-09-25T06:57:58.308799Z","shell.execute_reply.started":"2021-09-25T06:57:58.265762Z","shell.execute_reply":"2021-09-25T06:57:58.307947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = plays['quarter'].value_counts().reset_index()\n\ncheck.columns = [\n    'quarter', \n    'plays'\n]\n\ncheck = check.sort_values('plays')\n\nfig = px.pie(\n    check, \n    names='quarter', \n    values=\"plays\",  \n    title='Number of plays of every quarter',\n    height=500,\n    width=800\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:58:27.385706Z","iopub.execute_input":"2021-09-25T06:58:27.386786Z","iopub.status.idle":"2021-09-25T06:58:27.460164Z","shell.execute_reply.started":"2021-09-25T06:58:27.386739Z","shell.execute_reply":"2021-09-25T06:58:27.459387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = plays['down'].value_counts().reset_index()\n\ncheck.columns = [\n    'down', \n    'plays'\n]\n\ncheck = check.sort_values('plays')\n\nfig = px.pie(\n    check, \n    names='down', \n    values=\"plays\",  \n    title='Number of plays of every down',\n    height=500,\n    width=800\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:58:54.706002Z","iopub.execute_input":"2021-09-25T06:58:54.706316Z","iopub.status.idle":"2021-09-25T06:58:54.763242Z","shell.execute_reply.started":"2021-09-25T06:58:54.706284Z","shell.execute_reply":"2021-09-25T06:58:54.762351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check.columns = [\n    'yardsToGo', \n    'plays'\n]\n\ncheck['yardsToGo'] = check['yardsToGo'].astype(str) + '-'\ncheck = check.sort_values('plays')\n\nfig = px.bar(\n    check, \n    y='yardsToGo', \n    x=\"plays\", \n    orientation='h', \n    title='Number of plays for every yards to go category',\n    height=800,\n    width=800\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:59:15.420744Z","iopub.execute_input":"2021-09-25T06:59:15.421319Z","iopub.status.idle":"2021-09-25T06:59:15.488511Z","shell.execute_reply.started":"2021-09-25T06:59:15.42128Z","shell.execute_reply":"2021-09-25T06:59:15.487714Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = plays['possessionTeam'].value_counts().reset_index()\n\ncheck.columns = [\n    'team', \n    'plays'\n]\n\ncheck = check.sort_values('plays')\n\nfig = px.bar(\n    check, \n    y='team', \n    x=\"plays\", \n    orientation='h', \n    title='Number of plays for every team',\n    height=800,\n    width=800\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T06:59:49.666622Z","iopub.execute_input":"2021-09-25T06:59:49.667549Z","iopub.status.idle":"2021-09-25T06:59:49.756348Z","shell.execute_reply.started":"2021-09-25T06:59:49.667503Z","shell.execute_reply":"2021-09-25T06:59:49.755237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = plays['yardlineSide'].value_counts().reset_index()\n\ncheck.columns = [\n    'yardlineSide', \n    'plays'\n]\n\ncheck = check.sort_values('plays')\n\nfig = px.bar(\n    check, \n    y='yardlineSide', \n    x=\"plays\", \n    orientation='h', \n    title='Number of plays for every team yard side',\n    height=800,\n    width=800\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T07:00:19.546723Z","iopub.execute_input":"2021-09-25T07:00:19.547382Z","iopub.status.idle":"2021-09-25T07:00:19.619707Z","shell.execute_reply.started":"2021-09-25T07:00:19.547342Z","shell.execute_reply":"2021-09-25T07:00:19.618898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = plays['yardlineNumber'].value_counts().reset_index()\n\ncheck.columns = [\n    'yardline', \n    'plays'\n]\n\ncheck = check.sort_values('plays')\n\nfig = px.bar(\n    check, \n    x='yardline', \n    y=\"plays\",  \n    title='Number of plays for every yardline',\n    height=500,\n    width=800\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T07:00:43.210188Z","iopub.execute_input":"2021-09-25T07:00:43.210473Z","iopub.status.idle":"2021-09-25T07:00:43.280986Z","shell.execute_reply.started":"2021-09-25T07:00:43.210445Z","shell.execute_reply":"2021-09-25T07:00:43.280103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.histogram(\n    plays, \n    x='absoluteYardlineNumber',\n    width=800,\n    height=500,\n    nbins=50,\n    title='Absolute Yardline Number distribution'\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T07:01:03.701143Z","iopub.execute_input":"2021-09-25T07:01:03.701448Z","iopub.status.idle":"2021-09-25T07:01:03.875218Z","shell.execute_reply.started":"2021-09-25T07:01:03.701416Z","shell.execute_reply":"2021-09-25T07:01:03.874375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = plays['passResult'].value_counts().reset_index()\n\ncheck.columns = [\n    'passResult', \n    'plays'\n]\n\ncheck = check.sort_values('plays')\n\nfig = px.pie(\n    check, \n    names='passResult', \n    values=\"plays\",  \n    title='Number of plays for every pass result',\n    height=500,\n    width=800\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T07:01:23.780514Z","iopub.execute_input":"2021-09-25T07:01:23.781285Z","iopub.status.idle":"2021-09-25T07:01:23.837003Z","shell.execute_reply.started":"2021-09-25T07:01:23.781236Z","shell.execute_reply":"2021-09-25T07:01:23.836149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.histogram(\n    plays, \n    x=\"playResult\",\n    width=800,\n    height=500,\n    nbins=50,\n    title='Play result distribution'\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T07:01:49.450604Z","iopub.execute_input":"2021-09-25T07:01:49.450869Z","iopub.status.idle":"2021-09-25T07:01:49.591551Z","shell.execute_reply.started":"2021-09-25T07:01:49.450843Z","shell.execute_reply":"2021-09-25T07:01:49.59077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.histogram(\n    plays, \n    x=\"preSnapVisitorScore\",\n    width=800,\n    height=500,\n    nbins=50,\n    title='Pre Snap Visitor Score distribution'\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T07:02:08.025Z","iopub.execute_input":"2021-09-25T07:02:08.025599Z","iopub.status.idle":"2021-09-25T07:02:08.288801Z","shell.execute_reply.started":"2021-09-25T07:02:08.025553Z","shell.execute_reply":"2021-09-25T07:02:08.287817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.histogram(\n    plays, \n    x=\"preSnapHomeScore\",\n    width=800,\n    height=500,\n    nbins=50,\n    title='Pre Snap Home Score distribution'\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T07:02:28.835936Z","iopub.execute_input":"2021-09-25T07:02:28.836219Z","iopub.status.idle":"2021-09-25T07:02:28.97587Z","shell.execute_reply.started":"2021-09-25T07:02:28.836191Z","shell.execute_reply":"2021-09-25T07:02:28.975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"4. Football field visualization\nFor plays analysis I will use football field visualization","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport matplotlib.patches as patches\n\ndef create_football_field(\n    linenumbers=True,\n    endzones=True,\n    highlight_line=False,\n    highlight_line_number=50,\n    highlighted_name='Line of Scrimmage',\n    fifty_is_los=False,\n    figsize=(12, 6.33)\n):\n\n    rect = patches.Rectangle((0, 0), 120, 53.3, linewidth=0.1, edgecolor='r', facecolor='darkgreen', zorder=0)\n\n    fig, ax = plt.subplots(1, figsize=figsize)\n    ax.add_patch(rect)\n    plt.plot([10, 10, 10, 20, 20, 30, 30, 40, 40, 50, 50, 60, 60, 70, 70, 80,\n              80, 90, 90, 100, 100, 110, 110, 120, 0, 0, 120, 120],\n             [0, 0, 53.3, 53.3, 0, 0, 53.3, 53.3, 0, 0, 53.3, 53.3, 0, 0, 53.3,\n              53.3, 0, 0, 53.3, 53.3, 0, 0, 53.3, 53.3, 53.3, 0, 0, 53.3],\n             color='white')\n    if fifty_is_los:\n        plt.plot([60, 60], [0, 53.3], color='gold')\n        plt.text(62, 50, '<- Player Yardline at Snap', color='gold')\n \n    if endzones:\n        ez1 = patches.Rectangle((0, 0), 10, 53.3,\n                                linewidth=0.1,\n                                edgecolor='r',\n                                facecolor='blue',\n                                alpha=0.2,\n                                zorder=0)\n        ez2 = patches.Rectangle((110, 0), 120, 53.3,\n                                linewidth=0.1,\n                                edgecolor='r',\n                                facecolor='blue',\n                                alpha=0.2,\n                                zorder=0)\n        ax.add_patch(ez1)\n        ax.add_patch(ez2)\n    plt.xlim(0, 120)\n    plt.ylim(-5, 58.3)\n    plt.axis('off')\n    if linenumbers:\n        for x in range(20, 110, 10):\n            numb = x\n            if x > 50:\n                numb = 120 - x\n            plt.text(x, 5, str(numb - 10),\n                     horizontalalignment='center',\n                     fontsize=20,  # fontname='Arial',\n                     color='white')\n            plt.text(x - 0.95, 53.3 - 5, str(numb - 10),\n                     horizontalalignment='center',\n                     fontsize=20,  # fontname='Arial',\n                     color='white', rotation=180)\n    if endzones:\n        hash_range = range(11, 110)\n    else:\n        hash_range = range(1, 120)\n\n    for x in hash_range:\n        ax.plot([x, x], [0.4, 0.7], color='white')\n        ax.plot([x, x], [53.0, 52.5], color='white')\n        ax.plot([x, x], [22.91, 23.57], color='white')\n        ax.plot([x, x], [29.73, 30.39], color='white')\n    if highlight_line:\n        hl = highlight_line_number + 10\n        plt.plot([hl, hl], [0, 53.3], color='yellow')\n        plt.text(hl + 2, 50, '<- {}'.format(highlighted_name),\n                 color='yellow')\n    return fig, ax\n\ncreate_football_field()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-25T07:06:12.367993Z","iopub.execute_input":"2021-09-25T07:06:12.368293Z","iopub.status.idle":"2021-09-25T07:06:13.08475Z","shell.execute_reply.started":"2021-09-25T07:06:12.36824Z","shell.execute_reply":"2021-09-25T07:06:13.083946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}