{"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":"markdown","source":"<iframe src=\"https://www.kaggle.com/embed/hijest/nfl-big-data-bowl-2022-starters-eda?cellIds=1&kernelSessionId=75487025\" height=\"300\" style=\"margin: 0 auto; width: 100%; max-width: 950px;\" frameborder=\"0\" scrolling=\"auto\" title=\"NFL Big Data Bowl 2022 - Starters EDA 🏈🏈\"></iframe>","metadata":{}},{"cell_type":"markdown","source":"## NFL Big Data Bowl 2022 DATA ANALYSIS","metadata":{}},{"cell_type":"code","source":"\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport plotly.express as px\nfrom plotly.subplots import make_subplots\nimport plotly.graph_objs as go\n\npd.set_option('display.max_columns', None)\n","metadata":{"execution":{"iopub.status.busy":"2021-09-24T11:26:50.090567Z","iopub.execute_input":"2021-09-24T11:26:50.091778Z","iopub.status.idle":"2021-09-24T11:26:50.098335Z","shell.execute_reply.started":"2021-09-24T11:26:50.091724Z","shell.execute_reply":"2021-09-24T11:26:50.096996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Players Data","metadata":{}},{"cell_type":"code","source":"# Loading the dataset\nplayers = pd.read_csv('../input/nfl-big-data-bowl-2022/players.csv')","metadata":{"execution":{"iopub.status.busy":"2021-09-24T11:26:50.100179Z","iopub.execute_input":"2021-09-24T11:26:50.100498Z","iopub.status.idle":"2021-09-24T11:26:50.123161Z","shell.execute_reply.started":"2021-09-24T11:26:50.100467Z","shell.execute_reply":"2021-09-24T11:26:50.122477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Players csv contain there players data. The key variable is NLF-id\n\n* **nflid**       :  NLF-ID identififer numeric (Int 64) \n* **height**      :  Height of that player (Object)\n* **weight**      :  Height of that player (Int 64)\n* **birhtdate**   :  Data of Birth of that player (Object)\n* **collegeName** :  College name of the player (Object)\n* **Position**    :  Playing position of the player (Object)\n* **displayName** :  Display name of the player (Object)\n","metadata":{}},{"cell_type":"code","source":"\nprint(players.isnull().sum())\nplayers\n\n# We have null values in Birth data so lets check how we handle missing values","metadata":{"execution":{"iopub.status.busy":"2021-09-24T11:26:50.124497Z","iopub.execute_input":"2021-09-24T11:26:50.124809Z","iopub.status.idle":"2021-09-24T11:26:50.149394Z","shell.execute_reply.started":"2021-09-24T11:26:50.124778Z","shell.execute_reply":"2021-09-24T11:26:50.148517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Positions bar plot","metadata":{}},{"cell_type":"code","source":"plt.style.use(\"seaborn\")\n\ncolor=plt.cm.flag(np.linspace(0,2,4))\nplayers[\"Position\"].value_counts().plot.bar(color=color,figsize=(16,12))\n\nplt.title(\"number of positions of Players\")\nplt.xlabel('Position')\nplt.ylabel(\"total count\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-24T11:26:50.150842Z","iopub.execute_input":"2021-09-24T11:26:50.151748Z","iopub.status.idle":"2021-09-24T11:26:50.647805Z","shell.execute_reply.started":"2021-09-24T11:26:50.151705Z","shell.execute_reply":"2021-09-24T11:26:50.647175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# relationship between features\ncorr = players.corr()\nfig, ax = plt.subplots(figsize=(12,8))\nsns.heatmap(corr)","metadata":{"execution":{"iopub.status.busy":"2021-09-24T11:26:50.649752Z","iopub.execute_input":"2021-09-24T11:26:50.650214Z","iopub.status.idle":"2021-09-24T11:26:50.890441Z","shell.execute_reply.started":"2021-09-24T11:26:50.650173Z","shell.execute_reply":"2021-09-24T11:26:50.889813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ncheck = players['collegeName'].value_counts().reset_index()\n\ncheck.columns = [\n    'college', \n    'players'\n]\n\ncheck = check.sort_values('players').tail(40)\n\nfig = px.bar(\n    check, \n    y='college', \n    x=\"players\", \n    orientation='h', \n    title='Top 40 colleges by number of players',\n    height=900,\n    width=800\n)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-24T11:26:50.891728Z","iopub.execute_input":"2021-09-24T11:26:50.892180Z","iopub.status.idle":"2021-09-24T11:26:50.962029Z","shell.execute_reply.started":"2021-09-24T11:26:50.892140Z","shell.execute_reply":"2021-09-24T11:26:50.961229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Game data","metadata":{}},{"cell_type":"code","source":"game = pd.read_csv('../input/nfl-big-data-bowl-2022/games.csv')\ngame","metadata":{"execution":{"iopub.status.busy":"2021-09-24T11:31:04.654386Z","iopub.execute_input":"2021-09-24T11:31:04.654690Z","iopub.status.idle":"2021-09-24T11:31:04.676497Z","shell.execute_reply.started":"2021-09-24T11:31:04.654660Z","shell.execute_reply":"2021-09-24T11:31:04.675700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# No null values its good\nprint(game.isnull().sum())","metadata":{"execution":{"iopub.status.busy":"2021-09-24T11:29:03.401266Z","iopub.execute_input":"2021-09-24T11:29:03.401862Z","iopub.status.idle":"2021-09-24T11:29:03.411412Z","shell.execute_reply.started":"2021-09-24T11:29:03.401821Z","shell.execute_reply":"2021-09-24T11:29:03.410570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### game csv contains data for games records. The key variable is game-id\n\n* **game-id**     :  game-ID identififer numeric (Int 64) \n* **season**      : season (int 64)\n* **week**        :  Week of game (numeric) (Int 64)\n* **gamedate**    :  Data of game (Object)\n* **gameTimeEastern** :  Start time of game (time, HH:MM:SS, EST)\n* **visitorTeamAbbr**    : Visiting team three-letter code (text) (Object)","metadata":{}},{"cell_type":"markdown","source":"### games player per year(Season)","metadata":{}},{"cell_type":"code","source":"game[\"season\"].value_counts().plot.pie(figsize=(12,8),explode=(0.1,0.1,0.1),autopct=\"%1.1f%%\")\nplt.title(\"Games player per year (Season)\",fontsize=18)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-24T11:37:24.064875Z","iopub.execute_input":"2021-09-24T11:37:24.065730Z","iopub.status.idle":"2021-09-24T11:37:24.191758Z","shell.execute_reply.started":"2021-09-24T11:37:24.065683Z","shell.execute_reply":"2021-09-24T11:37:24.190800Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = game['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-09-24T11:38:25.057332Z","iopub.execute_input":"2021-09-24T11:38:25.058276Z","iopub.status.idle":"2021-09-24T11:38:25.130715Z","shell.execute_reply.started":"2021-09-24T11:38:25.058222Z","shell.execute_reply":"2021-09-24T11:38:25.129690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Play data","metadata":{}},{"cell_type":"markdown","source":"### \n* 24 features we have.\n* So many missing values be cafeful about them.\n","metadata":{}},{"cell_type":"code","source":"play = pd.read_csv(\"../input/nfl-big-data-bowl-2022/plays.csv\")\nplay","metadata":{"execution":{"iopub.status.busy":"2021-09-24T11:39:59.195219Z","iopub.execute_input":"2021-09-24T11:39:59.195504Z","iopub.status.idle":"2021-09-24T11:39:59.330178Z","shell.execute_reply.started":"2021-09-24T11:39:59.195466Z","shell.execute_reply":"2021-09-24T11:39:59.329240Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(play.isnull().sum())","metadata":{"execution":{"iopub.status.busy":"2021-09-24T11:41:09.489574Z","iopub.execute_input":"2021-09-24T11:41:09.490692Z","iopub.status.idle":"2021-09-24T11:41:09.518404Z","shell.execute_reply.started":"2021-09-24T11:41:09.490636Z","shell.execute_reply":"2021-09-24T11:41:09.517560Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play.info()","metadata":{"execution":{"iopub.status.busy":"2021-09-24T11:41:37.370104Z","iopub.execute_input":"2021-09-24T11:41:37.371246Z","iopub.status.idle":"2021-09-24T11:41:37.403199Z","shell.execute_reply.started":"2021-09-24T11:41:37.371205Z","shell.execute_reply":"2021-09-24T11:41:37.401978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = play['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)\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-24T11:48:57.094884Z","iopub.execute_input":"2021-09-24T11:48:57.095226Z","iopub.status.idle":"2021-09-24T11:48:57.180502Z","shell.execute_reply.started":"2021-09-24T11:48:57.095196Z","shell.execute_reply":"2021-09-24T11:48:57.178301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Corelation between features","metadata":{}},{"cell_type":"code","source":"# relationship between features\ncorr = play.corr()\nfig, ax = plt.subplots(figsize=(12,8))\nsns.heatmap(corr)","metadata":{"execution":{"iopub.status.busy":"2021-09-24T11:51:45.040088Z","iopub.execute_input":"2021-09-24T11:51:45.040995Z","iopub.status.idle":"2021-09-24T11:51:45.570894Z","shell.execute_reply.started":"2021-09-24T11:51:45.040930Z","shell.execute_reply":"2021-09-24T11:51:45.569685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Plotting missing values\n* These have missing values one have to handle.\n\n","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(8,6))\nmissing = play.isnull().sum()\nmissing = missing[missing > 0]\nmissing.sort_values(inplace=True)\nmissing.plot.bar(ax=ax)","metadata":{"execution":{"iopub.status.busy":"2021-09-24T11:53:09.786359Z","iopub.execute_input":"2021-09-24T11:53:09.786693Z","iopub.status.idle":"2021-09-24T11:53:10.087348Z","shell.execute_reply.started":"2021-09-24T11:53:09.786662Z","shell.execute_reply":"2021-09-24T11:53:10.086443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Heat map for missing values\n* Here we can see in this heat map how many values are missing.","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(10,8))\nsns.heatmap(play.isnull(), ax=ax)","metadata":{"execution":{"iopub.status.busy":"2021-09-24T11:53:41.010812Z","iopub.execute_input":"2021-09-24T11:53:41.011080Z","iopub.status.idle":"2021-09-24T11:53:42.586128Z","shell.execute_reply.started":"2021-09-24T11:53:41.011053Z","shell.execute_reply":"2021-09-24T11:53:42.585148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Play result distribution ","metadata":{}},{"cell_type":"code","source":"#To see how Play result distribution  is distributed\nplay[\"playResult\"].hist(figsize=(12,8),bins=15)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-24T12:00:57.669602Z","iopub.execute_input":"2021-09-24T12:00:57.669944Z","iopub.status.idle":"2021-09-24T12:00:57.920058Z","shell.execute_reply.started":"2021-09-24T12:00:57.669912Z","shell.execute_reply":"2021-09-24T12:00:57.919008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#preSnapHomeScore\n#To see how preSnapHomeScore is distributed\nplay[\"preSnapHomeScore\"].hist(figsize=(12,8),bins=15)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-24T12:00:40.639234Z","iopub.execute_input":"2021-09-24T12:00:40.639597Z","iopub.status.idle":"2021-09-24T12:00:41.144152Z","shell.execute_reply.started":"2021-09-24T12:00:40.639565Z","shell.execute_reply":"2021-09-24T12:00:41.143031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#To see how pre Snap Visitor Score is distributed\nplay[\"preSnapVisitorScore\"].hist(figsize=(12,8),bins=15)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-24T12:01:46.284414Z","iopub.execute_input":"2021-09-24T12:01:46.285320Z","iopub.status.idle":"2021-09-24T12:01:46.520017Z","shell.execute_reply.started":"2021-09-24T12:01:46.285250Z","shell.execute_reply":"2021-09-24T12:01:46.518956Z"},"trusted":true},"execution_count":null,"outputs":[]}]}