{"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-10-01T19:00:39.99752Z","iopub.execute_input":"2021-10-01T19:00:39.998005Z","iopub.status.idle":"2021-10-01T19:00:40.027553Z","shell.execute_reply.started":"2021-10-01T19:00:39.997924Z","shell.execute_reply":"2021-10-01T19:00:40.026736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 1. Dados do Jogo","metadata":{}},{"cell_type":"code","source":"games = pd.read_csv('../input/nfl-big-data-bowl-2022/games.csv')\ngames","metadata":{"execution":{"iopub.status.busy":"2021-10-01T19:01:28.627922Z","iopub.execute_input":"2021-10-01T19:01:28.628699Z","iopub.status.idle":"2021-10-01T19:01:28.664459Z","shell.execute_reply.started":"2021-10-01T19:01:28.628628Z","shell.execute_reply":"2021-10-01T19:01:28.663734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.express as px\nfrom plotly.subplots import make_subplots\nimport plotly.graph_objs as go","metadata":{"execution":{"iopub.status.busy":"2021-10-01T19:01:33.215795Z","iopub.execute_input":"2021-10-01T19:01:33.216699Z","iopub.status.idle":"2021-10-01T19:01:34.823391Z","shell.execute_reply.started":"2021-10-01T19:01:33.21665Z","shell.execute_reply":"2021-10-01T19:01:34.822443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = 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)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-10-01T19:01:39.70322Z","iopub.execute_input":"2021-10-01T19:01:39.704159Z","iopub.status.idle":"2021-10-01T19:01:40.811915Z","shell.execute_reply.started":"2021-10-01T19:01:39.704105Z","shell.execute_reply":"2021-10-01T19:01:40.8111Z"},"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)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-10-01T19:01:51.405512Z","iopub.execute_input":"2021-10-01T19:01:51.406325Z","iopub.status.idle":"2021-10-01T19:01:51.472364Z","shell.execute_reply.started":"2021-10-01T19:01:51.406288Z","shell.execute_reply":"2021-10-01T19:01:51.471804Z"},"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)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-10-01T19:02:13.174698Z","iopub.execute_input":"2021-10-01T19:02:13.175122Z","iopub.status.idle":"2021-10-01T19:02:13.242609Z","shell.execute_reply.started":"2021-10-01T19:02:13.175078Z","shell.execute_reply":"2021-10-01T19:02:13.241703Z"},"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)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-10-01T19:02:18.075045Z","iopub.execute_input":"2021-10-01T19:02:18.075317Z","iopub.status.idle":"2021-10-01T19:02:18.138875Z","shell.execute_reply.started":"2021-10-01T19:02:18.075291Z","shell.execute_reply":"2021-10-01T19:02:18.138332Z"},"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)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-10-01T19:02:23.631884Z","iopub.execute_input":"2021-10-01T19:02:23.632378Z","iopub.status.idle":"2021-10-01T19:02:23.697693Z","shell.execute_reply.started":"2021-10-01T19:02:23.632323Z","shell.execute_reply":"2021-10-01T19:02:23.696925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 2. Dados do Jogo","metadata":{}},{"cell_type":"code","source":"players = pd.read_csv('../input/nfl-big-data-bowl-2022/players.csv')\nplayers","metadata":{"execution":{"iopub.status.busy":"2021-10-01T19:02:38.205081Z","iopub.execute_input":"2021-10-01T19:02:38.205505Z","iopub.status.idle":"2021-10-01T19:02:38.238455Z","shell.execute_reply.started":"2021-10-01T19:02:38.205476Z","shell.execute_reply":"2021-10-01T19:02:38.237674Z"},"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-10-01T19:02:48.734416Z","iopub.execute_input":"2021-10-01T19:02:48.734976Z","iopub.status.idle":"2021-10-01T19:02:48.75127Z","shell.execute_reply.started":"2021-10-01T19:02:48.73494Z","shell.execute_reply":"2021-10-01T19:02:48.750533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 3. Dados do Jogo","metadata":{}},{"cell_type":"code","source":"plays = pd.read_csv('../input/nfl-big-data-bowl-2022/plays.csv')\n\nplays","metadata":{"execution":{"iopub.status.busy":"2021-09-25T01:05:18.550347Z","iopub.execute_input":"2021-09-25T01:05:18.550643Z","iopub.status.idle":"2021-09-25T01:05:18.722947Z","shell.execute_reply.started":"2021-09-25T01:05:18.550615Z","shell.execute_reply":"2021-09-25T01:05:18.722371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 4. Dados do Jogo","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\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\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-10-01T19:02:52.989701Z","iopub.execute_input":"2021-10-01T19:02:52.989959Z","iopub.status.idle":"2021-10-01T19:02:53.6769Z","shell.execute_reply.started":"2021-10-01T19:02:52.989932Z","shell.execute_reply":"2021-10-01T19:02:53.676345Z"},"trusted":true},"execution_count":null,"outputs":[]}]}