{"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-12T21:51:34.914697Z","iopub.execute_input":"2021-10-12T21:51:34.915045Z","iopub.status.idle":"2021-10-12T21:51:34.946687Z","shell.execute_reply.started":"2021-10-12T21:51:34.914952Z","shell.execute_reply":"2021-10-12T21:51:34.945556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# required packages ","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport seaborn as sns\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:51:34.948734Z","iopub.execute_input":"2021-10-12T21:51:34.949541Z","iopub.status.idle":"2021-10-12T21:51:35.854707Z","shell.execute_reply.started":"2021-10-12T21:51:34.949486Z","shell.execute_reply":"2021-10-12T21:51:35.853664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Functions to  display summary of the dataset:\n","metadata":{}},{"cell_type":"code","source":"def explore_numerical_types(df):\n    # SUMMARY\n    df_types = pd.DataFrame(df.dtypes, columns=['Data Type'])\n    numerical_cols = df_types[~df_types['Data Type'].isin(['object',\n                    'bool'])].index.values\n    df_types['Count'] = df.count()\n    df_types['Null Values'] = df.isnull().sum()\n    df_types['Unique Values'] = df.nunique()\n    df_types['Min'] = df[numerical_cols].min()\n    df_types['Max'] = df[numerical_cols].max()\n    df_types['Average'] = df[numerical_cols].mean()\n    df_types['Median'] = df[numerical_cols].median()\n    df_types['St. Dev.'] = df[numerical_cols].std()\n    return df_types","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:51:35.85617Z","iopub.execute_input":"2021-10-12T21:51:35.856625Z","iopub.status.idle":"2021-10-12T21:51:35.865066Z","shell.execute_reply.started":"2021-10-12T21:51:35.856591Z","shell.execute_reply":"2021-10-12T21:51:35.864131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# read csv files","metadata":{}},{"cell_type":"code","source":"players_df=pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/players.csv')\ngames_df = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/games.csv')\nplays_df = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/plays.csv')\ntracking_2018_df = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/tracking2018.csv')\n","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:51:35.866431Z","iopub.execute_input":"2021-10-12T21:51:35.866799Z","iopub.status.idle":"2021-10-12T21:52:24.335944Z","shell.execute_reply.started":"2021-10-12T21:51:35.866768Z","shell.execute_reply":"2021-10-12T21:52:24.335237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# read players_df","metadata":{}},{"cell_type":"code","source":"players_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:24.337699Z","iopub.execute_input":"2021-10-12T21:52:24.338623Z","iopub.status.idle":"2021-10-12T21:52:24.364972Z","shell.execute_reply.started":"2021-10-12T21:52:24.338587Z","shell.execute_reply":"2021-10-12T21:52:24.364027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"explore_numerical_types(players_df)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:24.36694Z","iopub.execute_input":"2021-10-12T21:52:24.367609Z","iopub.status.idle":"2021-10-12T21:52:24.425411Z","shell.execute_reply.started":"2021-10-12T21:52:24.367552Z","shell.execute_reply":"2021-10-12T21:52:24.424298Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = players_df['height'].str.split('-', expand=True)\ncheck.columns = ['first', 'second']\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-12T21:52:24.42735Z","iopub.execute_input":"2021-10-12T21:52:24.427939Z","iopub.status.idle":"2021-10-12T21:52:24.452314Z","shell.execute_reply.started":"2021-10-12T21:52:24.42789Z","shell.execute_reply":"2021-10-12T21:52:24.451262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"using the steps from *BAEK KYUN SHIN*[ here ](https://www.kaggle.com/werooring/nfl-big-data-bowl-basic-eda-for-beginner)\n\nin order to get 2 dicimal after the comma after converting feet to meters\n> players_df['height'] = pd.options.display.float_format = \"{:,.2f}\".format","metadata":{}},{"cell_type":"code","source":"players_df['height'] = check['first']\nplayers_df['height'] = players_df['height'].astype(np.float32)\nplayers_df['height'] /= 12\nplayers_df['height']/=3.288399\nplayers_df","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:24.45356Z","iopub.execute_input":"2021-10-12T21:52:24.453814Z","iopub.status.idle":"2021-10-12T21:52:24.483265Z","shell.execute_reply.started":"2021-10-12T21:52:24.453786Z","shell.execute_reply":"2021-10-12T21:52:24.481252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players_df[\"height\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:24.485944Z","iopub.execute_input":"2021-10-12T21:52:24.486194Z","iopub.status.idle":"2021-10-12T21:52:24.501388Z","shell.execute_reply.started":"2021-10-12T21:52:24.486167Z","shell.execute_reply":"2021-10-12T21:52:24.500776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 6))\nax = sns.histplot(players_df['height'], bins=12)\nax.set_title('Height Distribution');","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:24.502562Z","iopub.execute_input":"2021-10-12T21:52:24.502963Z","iopub.status.idle":"2021-10-12T21:52:24.85064Z","shell.execute_reply.started":"2021-10-12T21:52:24.502934Z","shell.execute_reply":"2021-10-12T21:52:24.849445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 6))\nax = sns.histplot(players_df['weight'], bins=12)\nax.set_title('weight Distribution');","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:24.852213Z","iopub.execute_input":"2021-10-12T21:52:24.852539Z","iopub.status.idle":"2021-10-12T21:52:25.114174Z","shell.execute_reply.started":"2021-10-12T21:52:24.852498Z","shell.execute_reply":"2021-10-12T21:52:25.112942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# convert \"birthDate\" field into date time type","metadata":{}},{"cell_type":"code","source":"# players_df['birthDate']=players_df['birthDate'].astype(\"datetime64\")\nplayers_df[\"birthDate\"]=pd.to_datetime(players_df[\"birthDate\"],dayfirst=True)\nplayers_df","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:25.116077Z","iopub.execute_input":"2021-10-12T21:52:25.116525Z","iopub.status.idle":"2021-10-12T21:52:25.143439Z","shell.execute_reply.started":"2021-10-12T21:52:25.116479Z","shell.execute_reply":"2021-10-12T21:52:25.14235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# set a standard format for the \"birthDate\" field","metadata":{}},{"cell_type":"code","source":"# players_df['birthDate'] = pd.to_datetime(players_df['birthDate'], format='%Y-%m-%d %H:%M:%S')\nplayers_df['birthDate'] = pd.to_datetime(players_df['birthDate'], format='%Y-%m-%d')\nplayers_df","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:25.145323Z","iopub.execute_input":"2021-10-12T21:52:25.14565Z","iopub.status.idle":"2021-10-12T21:52:25.172344Z","shell.execute_reply.started":"2021-10-12T21:52:25.145609Z","shell.execute_reply":"2021-10-12T21:52:25.171053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# check the summary for object  or boolean types ","metadata":{}},{"cell_type":"code","source":"players_df.describe(include=['object', 'bool'])","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:25.177366Z","iopub.execute_input":"2021-10-12T21:52:25.17762Z","iopub.status.idle":"2021-10-12T21:52:25.20272Z","shell.execute_reply.started":"2021-10-12T21:52:25.177585Z","shell.execute_reply":"2021-10-12T21:52:25.201647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# check the value counts of the \"position\" field","metadata":{}},{"cell_type":"code","source":"positions = players_df[\"Position\"].value_counts().to_frame()\npositions","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:25.204499Z","iopub.execute_input":"2021-10-12T21:52:25.205075Z","iopub.status.idle":"2021-10-12T21:52:25.219188Z","shell.execute_reply.started":"2021-10-12T21:52:25.205037Z","shell.execute_reply":"2021-10-12T21:52:25.217791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#plot\nplt.figure(figsize=(10, 6))\nsns.countplot(x=\"Position\",data=players_df)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:25.22075Z","iopub.execute_input":"2021-10-12T21:52:25.221017Z","iopub.status.idle":"2021-10-12T21:52:25.616596Z","shell.execute_reply.started":"2021-10-12T21:52:25.220987Z","shell.execute_reply":"2021-10-12T21:52:25.615224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# get the *year*  *month* *age* from the **birthDate** field ","metadata":{}},{"cell_type":"code","source":"# players_df[\"birthDate\"] = pd.to_datetime(players_df[\"birthDate\"],errors = 'coerce')\n# players_df['year_month'] = players_df['birthDate'].map(lambda x: x.strftime('%Y/%m'))\nplayers_df[\"year\"]=players_df[\"birthDate\"].dt.year\nplayers_df[\"month\"]=players_df[\"birthDate\"].dt.month\nplayers_df[\"is_leap_year\"]=players_df[\"birthDate\"].dt.is_leap_year\ntoday = pd.to_datetime(\"today\")\nplayers_df[\"age\"]=today.year - players_df[\"birthDate\"].dt.year\n\nplayers_df","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:25.618716Z","iopub.execute_input":"2021-10-12T21:52:25.619038Z","iopub.status.idle":"2021-10-12T21:52:25.663339Z","shell.execute_reply.started":"2021-10-12T21:52:25.618998Z","shell.execute_reply":"2021-10-12T21:52:25.66202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players_df.info()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:25.664939Z","iopub.execute_input":"2021-10-12T21:52:25.666773Z","iopub.status.idle":"2021-10-12T21:52:25.695613Z","shell.execute_reply.started":"2021-10-12T21:52:25.666731Z","shell.execute_reply":"2021-10-12T21:52:25.690074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players_df[\"year\"] =players_df[\"year\"].fillna(0)\nplayers_df[\"month\"]=players_df[\"month\"].fillna(0)\nplayers_df[\"age\"]= players_df[\"age\"].fillna(0)\n","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:25.697234Z","iopub.execute_input":"2021-10-12T21:52:25.697816Z","iopub.status.idle":"2021-10-12T21:52:25.707254Z","shell.execute_reply.started":"2021-10-12T21:52:25.69778Z","shell.execute_reply":"2021-10-12T21:52:25.706048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players_df['year']=players_df['year'].astype(\"int\")\nplayers_df['month']=players_df['month'].astype(\"int\")\nplayers_df['age']=players_df['age'].astype(\"int\")\n\n\nplayers_df.info()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:25.70901Z","iopub.execute_input":"2021-10-12T21:52:25.70944Z","iopub.status.idle":"2021-10-12T21:52:25.737663Z","shell.execute_reply.started":"2021-10-12T21:52:25.709398Z","shell.execute_reply":"2021-10-12T21:52:25.736147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* players age are min 22 years and max 49 \n* 13.9% are 26 years ","metadata":{}},{"cell_type":"code","source":"\nage = players_df[\"age\"].value_counts().rename_axis('age').reset_index(name='count')","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:25.739723Z","iopub.execute_input":"2021-10-12T21:52:25.740037Z","iopub.status.idle":"2021-10-12T21:52:25.755542Z","shell.execute_reply.started":"2021-10-12T21:52:25.739997Z","shell.execute_reply":"2021-10-12T21:52:25.754414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.graph_objects as go\n\nfig = go.Figure(data=[go.Pie(labels=age['age'],\n                             hoverinfo='label+percent',\n                             values=age['count'], \n                             textposition='outside', \n                             rotation=90)])\n\nfig.update_layout(title=\"Percentage of ages\",\n                  font=dict(family='Arial', size=12, color='#909090'),\n                  legend=dict(x=0.9, y=0.5)\n        )\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:25.756837Z","iopub.execute_input":"2021-10-12T21:52:25.757905Z","iopub.status.idle":"2021-10-12T21:52:26.018128Z","shell.execute_reply.started":"2021-10-12T21:52:25.757836Z","shell.execute_reply":"2021-10-12T21:52:26.017227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#plot\nplt.figure(figsize=(10, 6))\nsns.countplot(x=\"age\",data=players_df)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:26.019398Z","iopub.execute_input":"2021-10-12T21:52:26.019658Z","iopub.status.idle":"2021-10-12T21:52:26.397934Z","shell.execute_reply.started":"2021-10-12T21:52:26.01963Z","shell.execute_reply":"2021-10-12T21:52:26.397145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# check the collegeName and get the value count \nlooks like **alabama** college is recruiting the most players \n\n* plot a pie chart for the top 20","metadata":{}},{"cell_type":"code","source":"\ncol_df = players_df[\"collegeName\"].value_counts().rename_axis('collegeName').reset_index(name='count')\ncol_df_top = col_df[:20].copy()\ncol_df_top","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:26.399124Z","iopub.execute_input":"2021-10-12T21:52:26.399358Z","iopub.status.idle":"2021-10-12T21:52:26.415995Z","shell.execute_reply.started":"2021-10-12T21:52:26.39933Z","shell.execute_reply":"2021-10-12T21:52:26.415083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nimport plotly.graph_objects as go\n\nfig = go.Figure(data=[go.Pie(labels=col_df_top['collegeName'],\n                             hoverinfo='label+percent',\n                             values=col_df_top['count'], \n                             textposition='outside', \n                             rotation=90)])\n\nfig.update_layout(title=\"Percentage of collegename\",\n                  font=dict(family='Arial', size=12, color='#909090'),\n                  legend=dict(x=0.9, y=0.5)\n        )\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:26.417468Z","iopub.execute_input":"2021-10-12T21:52:26.418555Z","iopub.status.idle":"2021-10-12T21:52:26.443245Z","shell.execute_reply.started":"2021-10-12T21:52:26.418504Z","shell.execute_reply":"2021-10-12T21:52:26.442042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15, 12))\n\nax = sns.barplot(x='count', y='collegeName', data=col_df_top)\nax.set_title('Number of players for collegeName');","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:26.444777Z","iopub.execute_input":"2021-10-12T21:52:26.445116Z","iopub.status.idle":"2021-10-12T21:52:26.896152Z","shell.execute_reply.started":"2021-10-12T21:52:26.445065Z","shell.execute_reply":"2021-10-12T21:52:26.894894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# the most occupied position is **CB**  and most of players are in 26 ","metadata":{}},{"cell_type":"code","source":"fig = go.Figure()\nfor name ,group in players_df.groupby(\"age\"):\n    trace = go.Histogram()\n    trace.name = name\n    trace.x = group[\"Position\"]\n    fig.add_trace(trace)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:26.900302Z","iopub.execute_input":"2021-10-12T21:52:26.900606Z","iopub.status.idle":"2021-10-12T21:52:26.953369Z","shell.execute_reply.started":"2021-10-12T21:52:26.900574Z","shell.execute_reply":"2021-10-12T21:52:26.952228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#                                                 read games_df ","metadata":{}},{"cell_type":"code","source":"explore_numerical_types(games_df)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:26.95491Z","iopub.execute_input":"2021-10-12T21:52:26.955174Z","iopub.status.idle":"2021-10-12T21:52:26.99332Z","shell.execute_reply.started":"2021-10-12T21:52:26.955145Z","shell.execute_reply":"2021-10-12T21:52:26.992248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:26.994761Z","iopub.execute_input":"2021-10-12T21:52:26.995017Z","iopub.status.idle":"2021-10-12T21:52:27.010497Z","shell.execute_reply.started":"2021-10-12T21:52:26.994988Z","shell.execute_reply":"2021-10-12T21:52:27.009075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"each season the games increased slitly  between 2018 2020","metadata":{}},{"cell_type":"code","source":"games_df[\"season\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:27.011777Z","iopub.execute_input":"2021-10-12T21:52:27.011998Z","iopub.status.idle":"2021-10-12T21:52:27.021087Z","shell.execute_reply.started":"2021-10-12T21:52:27.011973Z","shell.execute_reply":"2021-10-12T21:52:27.020309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nsns.countplot(x = \"season\",data = games_df)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:27.022527Z","iopub.execute_input":"2021-10-12T21:52:27.02294Z","iopub.status.idle":"2021-10-12T21:52:27.241562Z","shell.execute_reply.started":"2021-10-12T21:52:27.022909Z","shell.execute_reply":"2021-10-12T21:52:27.24063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games_df['gameDate'] = pd.to_datetime(games_df['gameDate'])\n","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:27.242875Z","iopub.execute_input":"2021-10-12T21:52:27.243143Z","iopub.status.idle":"2021-10-12T21:52:27.252694Z","shell.execute_reply.started":"2021-10-12T21:52:27.243113Z","shell.execute_reply":"2021-10-12T21:52:27.251425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games_df.info()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:27.254856Z","iopub.execute_input":"2021-10-12T21:52:27.255503Z","iopub.status.idle":"2021-10-12T21:52:27.277591Z","shell.execute_reply.started":"2021-10-12T21:52:27.255456Z","shell.execute_reply":"2021-10-12T21:52:27.276344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games_df[\"year\"]=games_df[\"gameDate\"].dt.year\ngames_df[\"month\"]=games_df[\"gameDate\"].dt.month","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:27.279049Z","iopub.execute_input":"2021-10-12T21:52:27.27933Z","iopub.status.idle":"2021-10-12T21:52:27.298959Z","shell.execute_reply.started":"2021-10-12T21:52:27.279302Z","shell.execute_reply":"2021-10-12T21:52:27.298087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* December had the biguest number of games \n* january had the lowest number of games ","metadata":{}},{"cell_type":"code","source":"sns.countplot(x=\"month\",data=games_df)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:27.30022Z","iopub.execute_input":"2021-10-12T21:52:27.300465Z","iopub.status.idle":"2021-10-12T21:52:27.500877Z","shell.execute_reply.started":"2021-10-12T21:52:27.300438Z","shell.execute_reply":"2021-10-12T21:52:27.500088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games_df[\"homeTeamAbbr\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:27.502312Z","iopub.execute_input":"2021-10-12T21:52:27.503052Z","iopub.status.idle":"2021-10-12T21:52:27.512463Z","shell.execute_reply.started":"2021-10-12T21:52:27.503009Z","shell.execute_reply":"2021-10-12T21:52:27.511378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# read plays_df","metadata":{}},{"cell_type":"code","source":"explore_numerical_types(plays_df)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:27.513637Z","iopub.execute_input":"2021-10-12T21:52:27.513988Z","iopub.status.idle":"2021-10-12T21:52:27.634894Z","shell.execute_reply.started":"2021-10-12T21:52:27.513949Z","shell.execute_reply":"2021-10-12T21:52:27.633917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# most of the play type was kickoff ","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\n\nax = sns.countplot(x='specialTeamsPlayType', data=plays_df)\nax.set_title('specialTeamsPlayType');","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:27.635998Z","iopub.execute_input":"2021-10-12T21:52:27.636229Z","iopub.status.idle":"2021-10-12T21:52:27.888826Z","shell.execute_reply.started":"2021-10-12T21:52:27.636204Z","shell.execute_reply":"2021-10-12T21:52:27.887898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kickoff =plays_df.loc[plays_df[\"specialTeamsPlayType\"]==\"Kickoff\"]\nkickoff","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:52:27.890185Z","iopub.execute_input":"2021-10-12T21:52:27.89044Z","iopub.status.idle":"2021-10-12T21:52:27.935378Z","shell.execute_reply.started":"2021-10-12T21:52:27.890396Z","shell.execute_reply":"2021-10-12T21:52:27.934258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* 60% of the kickoffs are touchback\n* 37.2% of teh cickoff are return","metadata":{}},{"cell_type":"code","source":"kickoff = kickoff[\"specialTeamsResult\"].value_counts().rename_axis('specialTeamsResult').reset_index(name='count')\nkickoff","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:55:37.383192Z","iopub.execute_input":"2021-10-12T21:55:37.384153Z","iopub.status.idle":"2021-10-12T21:55:37.400956Z","shell.execute_reply.started":"2021-10-12T21:55:37.384106Z","shell.execute_reply":"2021-10-12T21:55:37.399966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = go.Figure(data=[go.Pie(labels=kickoff['specialTeamsResult'],\n                             hoverinfo='label+percent',\n                             values=kickoff['count'], \n                             textposition='outside', \n                             rotation=90)])\n\nfig.update_layout(title=\"Percentage of kickoffs\",\n                  font=dict(family='Arial', size=12, color='#909090'),\n                  legend=dict(x=0.9, y=0.5)\n        )\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:55:40.493949Z","iopub.execute_input":"2021-10-12T21:55:40.494308Z","iopub.status.idle":"2021-10-12T21:55:40.514781Z","shell.execute_reply.started":"2021-10-12T21:55:40.494275Z","shell.execute_reply":"2021-10-12T21:55:40.513714Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\n\nax = sns.countplot(x='quarter', data=plays_df)\nax.set_title('Number of plays of every quarter');","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:55:43.784508Z","iopub.execute_input":"2021-10-12T21:55:43.784823Z","iopub.status.idle":"2021-10-12T21:55:44.014893Z","shell.execute_reply.started":"2021-10-12T21:55:43.78478Z","shell.execute_reply":"2021-10-12T21:55:44.013982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\n\nax = sns.countplot(x='down', data=plays_df)\nax.set_title('Number of plays of every quarter');","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:55:45.303188Z","iopub.execute_input":"2021-10-12T21:55:45.303493Z","iopub.status.idle":"2021-10-12T21:55:45.525009Z","shell.execute_reply.started":"2021-10-12T21:55:45.303459Z","shell.execute_reply":"2021-10-12T21:55:45.524023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(14, 8))\n\nax = sns.countplot(x='yardsToGo', data=plays_df)\nax.set_title('Number of plays for every yards to go category');","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:55:46.47986Z","iopub.execute_input":"2021-10-12T21:55:46.480228Z","iopub.status.idle":"2021-10-12T21:55:46.974976Z","shell.execute_reply.started":"2021-10-12T21:55:46.480193Z","shell.execute_reply":"2021-10-12T21:55:46.974241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\n\nax = sns.histplot(plays_df['playResult'], bins = 25)\nax.set_title('playResult Distribution');","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:55:48.288625Z","iopub.execute_input":"2021-10-12T21:55:48.289847Z","iopub.status.idle":"2021-10-12T21:55:48.615859Z","shell.execute_reply.started":"2021-10-12T21:55:48.2898Z","shell.execute_reply":"2021-10-12T21:55:48.61462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" plt.figure(figsize=(12, 6))\n\nax = sns.histplot(plays_df['preSnapHomeScore'], bins = 12)\nax.set_title('preSnapHomeScore Distribution');","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:55:49.602848Z","iopub.execute_input":"2021-10-12T21:55:49.60315Z","iopub.status.idle":"2021-10-12T21:55:49.879802Z","shell.execute_reply.started":"2021-10-12T21:55:49.603121Z","shell.execute_reply":"2021-10-12T21:55:49.878952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" plt.figure(figsize=(12, 6))\n\nax = sns.histplot(plays_df['preSnapVisitorScore'], bins = 12)\nax.set_title('preSnapVisitorScore Distribution');","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:55:50.716321Z","iopub.execute_input":"2021-10-12T21:55:50.716644Z","iopub.status.idle":"2021-10-12T21:55:51.028613Z","shell.execute_reply.started":"2021-10-12T21:55:50.716613Z","shell.execute_reply":"2021-10-12T21:55:51.027344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# read tracking_2018_df","metadata":{}},{"cell_type":"code","source":"explore_numerical_types(tracking_2018_df)","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:55:53.715907Z","iopub.execute_input":"2021-10-12T21:55:53.716374Z","iopub.status.idle":"2021-10-12T21:56:23.150947Z","shell.execute_reply.started":"2021-10-12T21:55:53.716344Z","shell.execute_reply":"2021-10-12T21:56:23.149782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(12, 8))\ntracking_2018_df.query('gameId == 2018091001 and playId == 4033').groupby('team') \\\n    .plot(x='x', y='y', ax=ax, style='.')\nplt.legend().remove();","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:56:31.552579Z","iopub.execute_input":"2021-10-12T21:56:31.552904Z","iopub.status.idle":"2021-10-12T21:56:31.942411Z","shell.execute_reply.started":"2021-10-12T21:56:31.552872Z","shell.execute_reply":"2021-10-12T21:56:31.939684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(12, 8))\ntracking_2018_df.query('gameId == 2018091609 and position == \"CB\"').groupby('team') \\\n    .plot(x='x', y='y', ax=ax, style='.')\nplt.legend().remove();","metadata":{"execution":{"iopub.status.busy":"2021-10-12T21:56:33.588882Z","iopub.execute_input":"2021-10-12T21:56:33.58921Z","iopub.status.idle":"2021-10-12T21:56:34.462155Z","shell.execute_reply.started":"2021-10-12T21:56:33.589178Z","shell.execute_reply":"2021-10-12T21:56:34.461208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}