{"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":"import pandas as pd\nimport numpy as np\nimport seaborn as sb\nimport matplotlib.pyplot as plt\n# for colab\nimport os\nos.environ['KAGGLE_CONFIG_DIR']='/content'","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:01:59.173446Z","iopub.execute_input":"2021-12-19T09:01:59.173787Z","iopub.status.idle":"2021-12-19T09:01:59.178571Z","shell.execute_reply.started":"2021-12-19T09:01:59.173752Z","shell.execute_reply":"2021-12-19T09:01:59.177704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games = pd.read_csv('../input/nfl-big-data-bowl-2022/games.csv')\npff = pd.read_csv('../input/nfl-big-data-bowl-2022/PFFScoutingData.csv')\nplayers = pd.read_csv('../input/nfl-big-data-bowl-2022/players.csv')\nplays = pd.read_csv('../input/nfl-big-data-bowl-2022/plays.csv')","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:01:59.180533Z","iopub.execute_input":"2021-12-19T09:01:59.181243Z","iopub.status.idle":"2021-12-19T09:01:59.349696Z","shell.execute_reply.started":"2021-12-19T09:01:59.181207Z","shell.execute_reply":"2021-12-19T09:01:59.348697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checking the top 5 rows from games\ngames.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:01:59.351155Z","iopub.execute_input":"2021-12-19T09:01:59.351504Z","iopub.status.idle":"2021-12-19T09:01:59.364442Z","shell.execute_reply.started":"2021-12-19T09:01:59.351459Z","shell.execute_reply":"2021-12-19T09:01:59.363492Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"total_seasons=games['season'].value_counts().values.sum()\nseasons=games['season'].value_counts().index\nNo_of_games_per_season=games['season'].value_counts().values","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:01:59.366041Z","iopub.execute_input":"2021-12-19T09:01:59.366389Z","iopub.status.idle":"2021-12-19T09:01:59.381564Z","shell.execute_reply.started":"2021-12-19T09:01:59.366347Z","shell.execute_reply":"2021-12-19T09:01:59.380389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8,6))\nplt.pie(x=No_of_games_per_season,labels=seasons,colors=['green','orange','blue'],wedgeprops={'linewidth':2,'edgecolor':'k'},textprops={'fontweight':'bold'},autopct='%1.1f%%')\nplt.title('No of games per season',fontdict={'fontweight':'bold'})\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:01:59.383927Z","iopub.execute_input":"2021-12-19T09:01:59.384224Z","iopub.status.idle":"2021-12-19T09:01:59.550028Z","shell.execute_reply.started":"2021-12-19T09:01:59.38419Z","shell.execute_reply":"2021-12-19T09:01:59.549343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:01:59.5516Z","iopub.execute_input":"2021-12-19T09:01:59.551814Z","iopub.status.idle":"2021-12-19T09:01:59.57057Z","shell.execute_reply.started":"2021-12-19T09:01:59.551788Z","shell.execute_reply":"2021-12-19T09:01:59.569564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def bar_plot(col,df,cond,title):\n  plt.figure(figsize=(10,8))\n  sb.countplot(y=col,data=df,order=cond,palette='coolwarm_r')\n  plt.title(title,fontsize=16)\n  plt.show()\n    ","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:01:59.572573Z","iopub.execute_input":"2021-12-19T09:01:59.573487Z","iopub.status.idle":"2021-12-19T09:01:59.582252Z","shell.execute_reply.started":"2021-12-19T09:01:59.573432Z","shell.execute_reply":"2021-12-19T09:01:59.581334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"con=players['Position'].value_counts().index\nbar_plot('Position',players,con,'No of players wrt position')","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:01:59.583884Z","iopub.execute_input":"2021-12-19T09:01:59.584804Z","iopub.status.idle":"2021-12-19T09:01:59.933698Z","shell.execute_reply.started":"2021-12-19T09:01:59.584764Z","shell.execute_reply":"2021-12-19T09:01:59.932788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plays.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:01:59.935437Z","iopub.execute_input":"2021-12-19T09:01:59.935686Z","iopub.status.idle":"2021-12-19T09:01:59.963713Z","shell.execute_reply.started":"2021-12-19T09:01:59.935654Z","shell.execute_reply":"2021-12-19T09:01:59.963115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pff.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:01:59.964739Z","iopub.execute_input":"2021-12-19T09:01:59.965068Z","iopub.status.idle":"2021-12-19T09:01:59.988752Z","shell.execute_reply.started":"2021-12-19T09:01:59.96504Z","shell.execute_reply":"2021-12-19T09:01:59.987946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#merge1 = pd.merge(games,pff,on=['gameId','playId'])","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:01:59.989958Z","iopub.execute_input":"2021-12-19T09:01:59.990352Z","iopub.status.idle":"2021-12-19T09:02:00.021298Z","shell.execute_reply.started":"2021-12-19T09:01:59.990306Z","shell.execute_reply":"2021-12-19T09:02:00.020508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#merge1.dropna(how='all',axis=0, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:02:00.022525Z","iopub.execute_input":"2021-12-19T09:02:00.022875Z","iopub.status.idle":"2021-12-19T09:02:00.069899Z","shell.execute_reply.started":"2021-12-19T09:02:00.022845Z","shell.execute_reply":"2021-12-19T09:02:00.069218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"game_2018 = pd.read_csv('../input/nfl-big-data-bowl-2022/tracking2018.csv')","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:02:00.073003Z","iopub.execute_input":"2021-12-19T09:02:00.073325Z","iopub.status.idle":"2021-12-19T09:02:52.308795Z","shell.execute_reply.started":"2021-12-19T09:02:00.073251Z","shell.execute_reply":"2021-12-19T09:02:52.307311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"game_2019 = pd.read_csv('../input/nfl-big-data-bowl-2022/tracking2019.csv')","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:02:52.310004Z","iopub.execute_input":"2021-12-19T09:02:52.310293Z","iopub.status.idle":"2021-12-19T09:03:31.747017Z","shell.execute_reply.started":"2021-12-19T09:02:52.310233Z","shell.execute_reply":"2021-12-19T09:03:31.745208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"game_2020 = pd.read_csv('../input/nfl-big-data-bowl-2022/tracking2020.csv')","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:03:31.749463Z","iopub.execute_input":"2021-12-19T09:03:31.749777Z","iopub.status.idle":"2021-12-19T09:04:08.319778Z","shell.execute_reply.started":"2021-12-19T09:03:31.749743Z","shell.execute_reply":"2021-12-19T09:04:08.318704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"game_2018 = game_2018[game_2018['event']!=\"None\"]\ngame_2019 = game_2019[game_2019['event']!=\"None\"]\ngame_2020 = game_2020[game_2020['event']!=\"None\"]","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:04:08.32158Z","iopub.execute_input":"2021-12-19T09:04:08.321868Z","iopub.status.idle":"2021-12-19T09:04:15.435793Z","shell.execute_reply.started":"2021-12-19T09:04:08.321835Z","shell.execute_reply":"2021-12-19T09:04:15.434881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ff=game_2018.append(game_2019)","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:04:15.437116Z","iopub.execute_input":"2021-12-19T09:04:15.437373Z","iopub.status.idle":"2021-12-19T09:04:15.647681Z","shell.execute_reply.started":"2021-12-19T09:04:15.437343Z","shell.execute_reply":"2021-12-19T09:04:15.646663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ff=ff.append(game_2020)","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:04:15.648896Z","iopub.execute_input":"2021-12-19T09:04:15.649124Z","iopub.status.idle":"2021-12-19T09:04:15.839689Z","shell.execute_reply.started":"2021-12-19T09:04:15.649097Z","shell.execute_reply":"2021-12-19T09:04:15.838557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ff.shape","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:04:15.84108Z","iopub.execute_input":"2021-12-19T09:04:15.842106Z","iopub.status.idle":"2021-12-19T09:04:15.850432Z","shell.execute_reply.started":"2021-12-19T09:04:15.842051Z","shell.execute_reply":"2021-12-19T09:04:15.84929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#total_seasons=games['season'].value_counts().values.sum()\n","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:04:15.852186Z","iopub.execute_input":"2021-12-19T09:04:15.852511Z","iopub.status.idle":"2021-12-19T09:04:15.862208Z","shell.execute_reply.started":"2021-12-19T09:04:15.852399Z","shell.execute_reply":"2021-12-19T09:04:15.861212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"con=ff['event'].value_counts().index\nbar_plot('event',ff,con,'No of events')","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:04:15.863937Z","iopub.execute_input":"2021-12-19T09:04:15.864301Z","iopub.status.idle":"2021-12-19T09:04:18.58811Z","shell.execute_reply.started":"2021-12-19T09:04:15.864229Z","shell.execute_reply":"2021-12-19T09:04:18.587196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players['nflId'] = players['nflId'].apply(lambda x: float(x))","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:04:18.589237Z","iopub.execute_input":"2021-12-19T09:04:18.589464Z","iopub.status.idle":"2021-12-19T09:04:18.597662Z","shell.execute_reply.started":"2021-12-19T09:04:18.589438Z","shell.execute_reply":"2021-12-19T09:04:18.596336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players['nflId']","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:04:18.599334Z","iopub.execute_input":"2021-12-19T09:04:18.599713Z","iopub.status.idle":"2021-12-19T09:04:18.61552Z","shell.execute_reply.started":"2021-12-19T09:04:18.599659Z","shell.execute_reply":"2021-12-19T09:04:18.614681Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"merge1=pd.merge(ff,plays,on=['gameId', 'playId'],how='inner')","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:04:18.617058Z","iopub.execute_input":"2021-12-19T09:04:18.617506Z","iopub.status.idle":"2021-12-19T09:04:20.02273Z","shell.execute_reply.started":"2021-12-19T09:04:18.617468Z","shell.execute_reply":"2021-12-19T09:04:20.021734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#del merge1['passResult']\n#del merge1['penaltyCodes']\n#del merge1['penaltyJerseyNumbers']\n#del merge1['penaltyYards']\ndel merge1['kickBlockerId']","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:04:20.02398Z","iopub.execute_input":"2021-12-19T09:04:20.024222Z","iopub.status.idle":"2021-12-19T09:04:20.029831Z","shell.execute_reply.started":"2021-12-19T09:04:20.024192Z","shell.execute_reply":"2021-12-19T09:04:20.029152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"merge1","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:04:20.030778Z","iopub.execute_input":"2021-12-19T09:04:20.031443Z","iopub.status.idle":"2021-12-19T09:04:20.50044Z","shell.execute_reply.started":"2021-12-19T09:04:20.031403Z","shell.execute_reply":"2021-12-19T09:04:20.499656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players.drop('displayName',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:04:20.501451Z","iopub.execute_input":"2021-12-19T09:04:20.501843Z","iopub.status.idle":"2021-12-19T09:04:20.508656Z","shell.execute_reply.started":"2021-12-19T09:04:20.501805Z","shell.execute_reply":"2021-12-19T09:04:20.507742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"merge1=merge1.join(players.set_index('nflId'),on=['nflId'],how='inner')","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:04:20.510003Z","iopub.execute_input":"2021-12-19T09:04:20.510731Z","iopub.status.idle":"2021-12-19T09:04:21.931104Z","shell.execute_reply.started":"2021-12-19T09:04:20.510672Z","shell.execute_reply":"2021-12-19T09:04:21.930015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#merge1.drop('passResult',axis=1,inplace=True)\nmerge1.drop('collegeName',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:23:11.97429Z","iopub.execute_input":"2021-12-19T09:23:11.974605Z","iopub.status.idle":"2021-12-19T09:23:12.313086Z","shell.execute_reply.started":"2021-12-19T09:23:11.974569Z","shell.execute_reply":"2021-12-19T09:23:12.312093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"con=merge1['event'].value_counts().index\ncon2=merge1['event'].value_counts().index\nbar_plot('event',merge1,con,'No of events')","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:06:29.303771Z","iopub.execute_input":"2021-12-19T09:06:29.304442Z","iopub.status.idle":"2021-12-19T09:06:32.208857Z","shell.execute_reply.started":"2021-12-19T09:06:29.304388Z","shell.execute_reply":"2021-12-19T09:06:32.207871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}