{"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":"<br>\n<h1 style = \"font-size:60px; font-family:Garamond ; font-weight : normal; background-color: #f6f5f5 ; color : #fe346e; text-align: center; border-radius: 100px 100px;\"> MLB Player-Digi Engagement Forecasting · Quicklook  <br> Data Analysis & Insights </h1>\n<br>","metadata":{}},{"cell_type":"markdown","source":"# Data Description \n\nYou are tasked with forecasting four different measures of engagement (target1-target4) for a subset of MLB players who are active in the 2021 season. The data contains a set of static files that do not change with time (players.csv, teams.csv, seasons.csv, awards.csv) as well as daily data (train.csv) which is grouped by day. When predicting on a given date, you are forecasting the target variables for the next day (i.e. for date d, you're predicting the engagement for day d+1).\n\nThis is a code competition that relies on a time-series module to ensure models do not peek forward in time. The time series module provides you with the test data and writes your submission file automatically. The test data arrives in a data frame identical in format to train.csv, except it does not contain the target values. To submit, follow the instructions on the Evaluation page. When you submit your notebook, it will be rerun on an unseen test set:\n\nDuring the Training phase of the competition, this unseen test set is comprised of data for the month of May 2021 and the set of active players this year.\nDuring the Evaluation phase, the test set will be a future in-season range of approximately one month.\nYour code will need to be robust and make predictions for any date_playerId combination requested by the module. Each team's selected notebooks (up to 2 per team, selected by the Final Submission Deadline) will be rerun during the Evaluation phase.\n\nBefore diving into specifics, some high level qualifications about the data:\n\nSome self-explanatory fields do not have an explanation (for example: season)\nBinary columns will have null values as well as zeroes. Zeroes will occur if a player had an opportunity to do something, but did not. Nulls will occur if a player never had the opportunity to do something (for example: a player who does not pitch on a given day cannot possibly pitch a shutout - therefore a null value is expected)\nMost game state related fields (balls, strikes, outs, etc.) represent the game state after the event in question. Home score and away score, however, represent the score before an event.\n\n\n\nWe are given 7 csv files:-\n\n - train.csv:training set\n - example_test.csv:example of test set\n - example_sample_submission.csv:example of sample_submission\n - awards.csv:awards won by players before 2018\n - players.csv:Library high level information about all players.\n - seasons.csv:Information about start and end dates of all seasons in this dataset\n - teams.csv:Library containing high level information about all MLB teams.","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"!pip install -q sweetviz\n!pip install -q klib\n!pip install -q raceplotly","metadata":{"execution":{"iopub.status.busy":"2021-06-12T06:04:32.645662Z","iopub.execute_input":"2021-06-12T06:04:32.646077Z","iopub.status.idle":"2021-06-12T06:04:46.685357Z","shell.execute_reply.started":"2021-06-12T06:04:32.646033Z","shell.execute_reply":"2021-06-12T06:04:46.684166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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)\nfrom tqdm import tqdm\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\nfrom sklearn.preprocessing import MinMaxScaler,StandardScaler\n\nimport klib\nimport seaborn as sns\n\n# Data Visualisation libraries \n%matplotlib inline\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nfrom raceplotly.plots import barplot\n\nsns.set(rc={'figure.figsize':(20.7,20.27)})\n\n\nimport plotly.express as px\nimport plotly.graph_objects as go\nimport plotly.figure_factory as ff\nfrom plotly.subplots import make_subplots\nfrom plotly.offline import init_notebook_mode, iplot\ninit_notebook_mode(connected=True)\n\nimport warnings\nwarnings.filterwarnings(\"ignore\")","metadata":{"execution":{"iopub.status.busy":"2021-06-12T09:44:32.182309Z","iopub.execute_input":"2021-06-12T09:44:32.182703Z","iopub.status.idle":"2021-06-12T09:44:32.199122Z","shell.execute_reply.started":"2021-06-12T09:44:32.182671Z","shell.execute_reply":"2021-06-12T09:44:32.197899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import 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":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players = pd.read_csv('../input/mlb-player-digital-engagement-forecasting/players.csv')\nseasons = pd.read_csv('../input/mlb-player-digital-engagement-forecasting/seasons.csv')\nawards = pd.read_csv('../input/mlb-player-digital-engagement-forecasting/awards.csv')\nteams = pd.read_csv('../input/mlb-player-digital-engagement-forecasting/teams.csv')\ntrain = pd.read_csv('../input/mlb-player-digital-engagement-forecasting/train.csv')","metadata":{"execution":{"iopub.status.busy":"2021-06-12T05:49:29.878318Z","iopub.execute_input":"2021-06-12T05:49:29.878920Z","iopub.status.idle":"2021-06-12T05:50:52.542612Z","shell.execute_reply.started":"2021-06-12T05:49:29.878861Z","shell.execute_reply":"2021-06-12T05:50:52.541190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-12T05:51:02.115861Z","iopub.execute_input":"2021-06-12T05:51:02.116471Z","iopub.status.idle":"2021-06-12T05:51:02.174630Z","shell.execute_reply.started":"2021-06-12T05:51:02.116433Z","shell.execute_reply":"2021-06-12T05:51:02.173318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2021-06-12T05:51:23.825508Z","iopub.execute_input":"2021-06-12T05:51:23.826134Z","iopub.status.idle":"2021-06-12T05:51:23.857880Z","shell.execute_reply.started":"2021-06-12T05:51:23.826085Z","shell.execute_reply":"2021-06-12T05:51:23.856744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"N_DATES = train.shape[0]\nd = []\nfor idx in tqdm(range(N_DATES)):\n    u = eval(train.iloc[idx, 1])\n    d += u\ntrain_next_day = pd.DataFrame(d)\ntrain_next_day.engagementMetricsDate = train_next_day.engagementMetricsDate.astype('datetime64[ns]')","metadata":{"execution":{"iopub.status.busy":"2021-06-12T05:59:56.948969Z","iopub.execute_input":"2021-06-12T05:59:56.949747Z","iopub.status.idle":"2021-06-12T06:01:14.907041Z","shell.execute_reply.started":"2021-06-12T05:59:56.949691Z","shell.execute_reply":"2021-06-12T06:01:14.905843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_next_day.groupby(['engagementMetricsDate']).agg({'playerId':'count'})","metadata":{"execution":{"iopub.status.busy":"2021-06-12T06:07:57.977265Z","iopub.execute_input":"2021-06-12T06:07:57.977711Z","iopub.status.idle":"2021-06-12T06:07:58.064741Z","shell.execute_reply.started":"2021-06-12T06:07:57.977674Z","shell.execute_reply":"2021-06-12T06:07:58.063217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_next_day['engagementMetricsDate_day'] = train_next_day['engagementMetricsDate'].dt.day\ntrain_next_day['engagementMetricsDate_month'] = train_next_day['engagementMetricsDate'].dt.month\ntrain_next_day['engagementMetricsDate_year'] = train_next_day['engagementMetricsDate'].dt.year\ntrain_next_day['engagementMetricsDate_week'] = train_next_day['engagementMetricsDate'].dt.weekofyear","metadata":{"execution":{"iopub.status.busy":"2021-06-12T06:11:41.965944Z","iopub.execute_input":"2021-06-12T06:11:41.966544Z","iopub.status.idle":"2021-06-12T06:11:42.978155Z","shell.execute_reply.started":"2021-06-12T06:11:41.966488Z","shell.execute_reply":"2021-06-12T06:11:42.977098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plyr_eng_agg_years = train_next_day.groupby(['engagementMetricsDate_year','engagementMetricsDate_month']).agg({'target1':'mean',\\\n                                                                                                     'target2':'mean',\\\n                                                                                                     'target3':'mean',\\\n                                                                                                     'target4':'mean'                                                                                         \n                                                                                                    }).reset_index()","metadata":{"execution":{"iopub.status.busy":"2021-06-12T06:21:24.184718Z","iopub.execute_input":"2021-06-12T06:21:24.185237Z","iopub.status.idle":"2021-06-12T06:21:24.383374Z","shell.execute_reply.started":"2021-06-12T06:21:24.185191Z","shell.execute_reply":"2021-06-12T06:21:24.382324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plyr_eng_agg_years_tgt1 =  plyr_eng_agg_years.pivot(index='engagementMetricsDate_year',columns=['engagementMetricsDate_month'],values=['target1']).reset_index()","metadata":{"execution":{"iopub.status.busy":"2021-06-12T06:32:27.379524Z","iopub.execute_input":"2021-06-12T06:32:27.379890Z","iopub.status.idle":"2021-06-12T06:32:27.390063Z","shell.execute_reply.started":"2021-06-12T06:32:27.379858Z","shell.execute_reply":"2021-06-12T06:32:27.388422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plyr_eng_agg_years_tgt1[['engagementMetricsDate_year','target1']]","metadata":{"execution":{"iopub.status.busy":"2021-06-12T06:32:56.031315Z","iopub.execute_input":"2021-06-12T06:32:56.032104Z","iopub.status.idle":"2021-06-12T06:32:56.057457Z","shell.execute_reply.started":"2021-06-12T06:32:56.032045Z","shell.execute_reply":"2021-06-12T06:32:56.056644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.concat([plyr_eng_agg_years_tgt1.engagementMetricsDate_year,plyr_eng_agg_years_tgt1.target1],axis=1)","metadata":{"execution":{"iopub.status.busy":"2021-06-12T06:34:51.491176Z","iopub.execute_input":"2021-06-12T06:34:51.491551Z","iopub.status.idle":"2021-06-12T06:34:51.517267Z","shell.execute_reply.started":"2021-06-12T06:34:51.491519Z","shell.execute_reply":"2021-06-12T06:34:51.516163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Observation - \n \n*   Players are pretty engaged from March to September \n*   Jan,Feb,Oct,Nov & Dec are less engaged\n*   Year - 2020 , Due to Covid19 Players are less engaged compared to 2018 & 2019\n*   2021- Engagement is back normal ","metadata":{}},{"cell_type":"markdown","source":"### Univariate Analysis into Target Variables :-","metadata":{}},{"cell_type":"code","source":"klib.dist_plot(train_next_day['target1'])","metadata":{"execution":{"iopub.status.busy":"2021-06-12T06:05:12.141177Z","iopub.execute_input":"2021-06-12T06:05:12.141595Z","iopub.status.idle":"2021-06-12T06:05:13.347015Z","shell.execute_reply.started":"2021-06-12T06:05:12.141560Z","shell.execute_reply":"2021-06-12T06:05:13.345816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Player dataset Analysis ;-","metadata":{}},{"cell_type":"code","source":"klib.missingval_plot(players)","metadata":{"execution":{"iopub.status.busy":"2021-06-12T07:26:18.438353Z","iopub.execute_input":"2021-06-12T07:26:18.438829Z","iopub.status.idle":"2021-06-12T07:26:19.885726Z","shell.execute_reply.started":"2021-06-12T07:26:18.438790Z","shell.execute_reply":"2021-06-12T07:26:19.884300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Obervation :- \n* 25% Birth State province is missing in dataset \n* 3% of mlbDebutDate is missing","metadata":{}},{"cell_type":"markdown","source":"# Players Distribution by BirthCountry","metadata":{}},{"cell_type":"code","source":"source = players['birthCountry'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-06-12T07:30:44.027866Z","iopub.execute_input":"2021-06-12T07:30:44.028653Z","iopub.status.idle":"2021-06-12T07:30:44.035191Z","shell.execute_reply.started":"2021-06-12T07:30:44.028600Z","shell.execute_reply":"2021-06-12T07:30:44.034328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#players['birthCountry'].value_counts()\nfig = go.Figure(data=[go.Pie(labels=source.index,values=source.values)])\nfig.update_layout(title='BirthCountry distribution')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-12T07:32:58.184799Z","iopub.execute_input":"2021-06-12T07:32:58.185253Z","iopub.status.idle":"2021-06-12T07:32:58.207024Z","shell.execute_reply.started":"2021-06-12T07:32:58.185211Z","shell.execute_reply":"2021-06-12T07:32:58.205358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Observation :- \n* 85% of Players birthcountry is USA,D.Republic ,Venezuela & Cuba ","metadata":{}},{"cell_type":"code","source":"src1=players['primaryPositionName'].value_counts()\n#players['birthCountry'].value_counts()\nfig = go.Figure(data=[go.Pie(labels=src1.index,values=src1.values)])\nfig.update_layout(title='primaryPositionName distribution')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-12T07:42:18.754227Z","iopub.execute_input":"2021-06-12T07:42:18.754560Z","iopub.status.idle":"2021-06-12T07:42:18.775022Z","shell.execute_reply.started":"2021-06-12T07:42:18.754530Z","shell.execute_reply":"2021-06-12T07:42:18.773952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Observation :- \n* Majority of players playing Picher,Outfielder,Catcher,Second & First based\n* Very few belongs to Designated Hitter & Infield","metadata":{}},{"cell_type":"code","source":"players.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-12T07:48:03.496577Z","iopub.execute_input":"2021-06-12T07:48:03.496945Z","iopub.status.idle":"2021-06-12T07:48:03.517454Z","shell.execute_reply.started":"2021-06-12T07:48:03.496915Z","shell.execute_reply":"2021-06-12T07:48:03.516601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Bivariate analysis in Player Dataset","metadata":{}},{"cell_type":"code","source":"scaler = MinMaxScaler()\nscaled_values = scaler.fit_transform(players[['heightInches','weight']])\nplayers = pd.concat([players,pd.DataFrame(scaled_values,columns=['heightInches_minmax','weight_min_max'])],axis=1)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(30, 30))\nsns.pairplot(players[['primaryPositionName','heightInches','weight']],hue='primaryPositionName')","metadata":{"execution":{"iopub.status.busy":"2021-06-12T07:51:14.713377Z","iopub.execute_input":"2021-06-12T07:51:14.713814Z","iopub.status.idle":"2021-06-12T07:51:16.857804Z","shell.execute_reply.started":"2021-06-12T07:51:14.713775Z","shell.execute_reply":"2021-06-12T07:51:16.856583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(30, 30))\nsns.pairplot(players[['primaryPositionName','heightInches_minmax','weight_min_max']],hue='primaryPositionName')","metadata":{"execution":{"iopub.status.busy":"2021-06-12T08:07:51.924012Z","iopub.execute_input":"2021-06-12T08:07:51.924567Z","iopub.status.idle":"2021-06-12T08:07:54.066147Z","shell.execute_reply.started":"2021-06-12T08:07:51.924517Z","shell.execute_reply":"2021-06-12T08:07:54.064940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Observation :- \n    Pichers have positive correlation Weight vs Height Inches ","metadata":{}},{"cell_type":"code","source":"players['DOB'] = pd.to_datetime(players['DOB'])\nplayers['Age']=2021-players['DOB'].dt.year","metadata":{"execution":{"iopub.status.busy":"2021-06-12T08:11:58.380533Z","iopub.execute_input":"2021-06-12T08:11:58.381173Z","iopub.status.idle":"2021-06-12T08:11:58.388230Z","shell.execute_reply.started":"2021-06-12T08:11:58.381137Z","shell.execute_reply":"2021-06-12T08:11:58.387262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = go.Figure(data=[go.Box(x=players.primaryPositionName, y=players.Age)])\nfig.update_layout(title='primaryPositionName vs Age')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-12T08:21:23.512821Z","iopub.execute_input":"2021-06-12T08:21:23.513261Z","iopub.status.idle":"2021-06-12T08:21:23.554141Z","shell.execute_reply.started":"2021-06-12T08:21:23.513221Z","shell.execute_reply":"2021-06-12T08:21:23.553335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for pos in players.primaryPositionName.unique().tolist():\n    print(\" Avg Age of \",pos,\"=\",round(players.loc[players['primaryPositionName']==pos]['Age'].mean(),0))","metadata":{"execution":{"iopub.status.busy":"2021-06-12T08:28:28.338363Z","iopub.execute_input":"2021-06-12T08:28:28.338723Z","iopub.status.idle":"2021-06-12T08:28:28.368507Z","shell.execute_reply.started":"2021-06-12T08:28:28.338694Z","shell.execute_reply":"2021-06-12T08:28:28.367171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for pos in players.primaryPositionName.unique().tolist():\n    print(\" primaryPositionName = \",pos)\n    klib.dist_plot(players.loc[players['primaryPositionName']==pos]['Age'])","metadata":{"execution":{"iopub.status.busy":"2021-06-12T08:29:09.786176Z","iopub.execute_input":"2021-06-12T08:29:09.786628Z","iopub.status.idle":"2021-06-12T08:29:13.068459Z","shell.execute_reply.started":"2021-06-12T08:29:09.786593Z","shell.execute_reply":"2021-06-12T08:29:13.067523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Observation :- \n* Designated hitters are pretty experianced min.32 & max 43 with Avg 36.5 years \n* Other Player positions Age boradly varies from 25-33 years ","metadata":{}},{"cell_type":"code","source":"players[['primaryPositionName','heightInches_minmax','weight_min_max']]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(30, 30))\nsns.jointplot(players['heightInches_minmax'],players['weight_min_max'],hue=players['primaryPositionName'])","metadata":{"execution":{"iopub.status.busy":"2021-06-12T09:09:55.039568Z","iopub.execute_input":"2021-06-12T09:09:55.040184Z","iopub.status.idle":"2021-06-12T09:09:57.358118Z","shell.execute_reply.started":"2021-06-12T09:09:55.040147Z","shell.execute_reply":"2021-06-12T09:09:57.356994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"## Let see what is there in Teams dataset","metadata":{}},{"cell_type":"code","source":"teams.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-06-12T08:38:41.623686Z","iopub.execute_input":"2021-06-12T08:38:41.624299Z","iopub.status.idle":"2021-06-12T08:38:41.643671Z","shell.execute_reply.started":"2021-06-12T08:38:41.624262Z","shell.execute_reply":"2021-06-12T08:38:41.642913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"klib.missingval_plot(teams)","metadata":{"execution":{"iopub.status.busy":"2021-06-12T08:39:09.531352Z","iopub.execute_input":"2021-06-12T08:39:09.531765Z","iopub.status.idle":"2021-06-12T08:39:09.541186Z","shell.execute_reply.started":"2021-06-12T08:39:09.531730Z","shell.execute_reply":"2021-06-12T08:39:09.540159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"klib.cat_plot(teams)","metadata":{"execution":{"iopub.status.busy":"2021-06-12T08:39:46.063207Z","iopub.execute_input":"2021-06-12T08:39:46.063618Z","iopub.status.idle":"2021-06-12T08:39:48.325564Z","shell.execute_reply.started":"2021-06-12T08:39:46.063583Z","shell.execute_reply":"2021-06-12T08:39:48.324673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"teams['locationName'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-06-12T08:45:22.148842Z","iopub.execute_input":"2021-06-12T08:45:22.149633Z","iopub.status.idle":"2021-06-12T08:45:22.159012Z","shell.execute_reply.started":"2021-06-12T08:45:22.149592Z","shell.execute_reply":"2021-06-12T08:45:22.158025Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Let look into Awards","metadata":{}},{"cell_type":"code","source":"award_with_team = awards.merge(teams[['id','name', 'teamName','leagueName', 'divisionId', 'divisionName']],left_on='awardPlayerTeamId',right_on='id')\naward_with_team_agg =  award_with_team.groupby(['awardSeason','name']).agg({'divisionName':'count','awardSeason':'min'}).rename(columns={'divisionName':'Award_count','awardSeason':'min_award_year'}).reset_index()","metadata":{"execution":{"iopub.status.busy":"2021-06-12T09:29:37.082284Z","iopub.execute_input":"2021-06-12T09:29:37.082784Z","iopub.status.idle":"2021-06-12T09:29:37.108249Z","shell.execute_reply.started":"2021-06-12T09:29:37.082707Z","shell.execute_reply":"2021-06-12T09:29:37.107142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"my_raceplot = barplot(award_with_team_agg,  item_column='name', value_column='Award_count', time_column='awardSeason')\nmy_raceplot.plot(item_label = 'team name', value_label = 'Award Count', frame_duration = 800)","metadata":{"execution":{"iopub.status.busy":"2021-06-12T09:04:35.092845Z","iopub.execute_input":"2021-06-12T09:04:35.093400Z","iopub.status.idle":"2021-06-12T09:04:35.278938Z","shell.execute_reply.started":"2021-06-12T09:04:35.093367Z","shell.execute_reply":"2021-06-12T09:04:35.277834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"award_with_team.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-12T09:48:39.154892Z","iopub.execute_input":"2021-06-12T09:48:39.155314Z","iopub.status.idle":"2021-06-12T09:48:39.176566Z","shell.execute_reply.started":"2021-06-12T09:48:39.155279Z","shell.execute_reply":"2021-06-12T09:48:39.175512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"award_with_team_agg.pivot(index='name',columns='awardSeason',values='Award_count').fillna(0)","metadata":{"execution":{"iopub.status.busy":"2021-06-12T09:30:31.811449Z","iopub.execute_input":"2021-06-12T09:30:31.811800Z","iopub.status.idle":"2021-06-12T09:30:31.901153Z","shell.execute_reply.started":"2021-06-12T09:30:31.811770Z","shell.execute_reply":"2021-06-12T09:30:31.899403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(award_with_team_agg.pivot(index='name',columns='awardSeason',values='Award_count').fillna(0))","metadata":{"execution":{"iopub.status.busy":"2021-06-12T09:08:40.114215Z","iopub.execute_input":"2021-06-12T09:08:40.114614Z","iopub.status.idle":"2021-06-12T09:08:41.042920Z","shell.execute_reply.started":"2021-06-12T09:08:40.114582Z","shell.execute_reply":"2021-06-12T09:08:41.042053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Observations :-\n* Chicogo Tigers & Auston Astros got maximum awards in 2015 & 2017 compared to other teams","metadata":{}},{"cell_type":"markdown","source":"### Team Cohort in Awards","metadata":{}},{"cell_type":"code","source":"award_with_team.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-12T09:18:40.675262Z","iopub.execute_input":"2021-06-12T09:18:40.675682Z","iopub.status.idle":"2021-06-12T09:18:40.699728Z","shell.execute_reply.started":"2021-06-12T09:18:40.675651Z","shell.execute_reply":"2021-06-12T09:18:40.698799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.concat(\n    [\n        award_with_team.groupby(['name']).agg({'divisionName':'count','awardDate':'min'}).rename(columns={'divisionName':'Award_count','awardSeason':'min_award_year','awardDate':'awardDate_min'}),\n        award_with_team_agg.pivot(index='name',columns='awardSeason',values='Award_count').fillna(0)\n    ],\n    axis=1\n).reset_index()","metadata":{"execution":{"iopub.status.busy":"2021-06-12T09:35:23.728503Z","iopub.execute_input":"2021-06-12T09:35:23.729093Z","iopub.status.idle":"2021-06-12T09:35:23.827393Z","shell.execute_reply.started":"2021-06-12T09:35:23.729043Z","shell.execute_reply":"2021-06-12T09:35:23.826233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Players Award Churn in History","metadata":{}},{"cell_type":"code","source":"award_with_team.groupby(['awardSeason','playerName'])\\\n.agg({'divisionName':'count'}).rename(columns={'divisionName':'Award_count','awardSeason':'min_award_year','awardDate':'awardDate_min'})\\\n.reset_index()\\\n.sort_values('Award_count',ascending=False)\\\n.head(500)\\\n.pivot(index='playerName',columns='awardSeason',values='Award_count')\\\n.fillna(0)","metadata":{"execution":{"iopub.status.busy":"2021-06-12T09:43:17.190300Z","iopub.execute_input":"2021-06-12T09:43:17.190856Z","iopub.status.idle":"2021-06-12T09:43:17.244234Z","shell.execute_reply.started":"2021-06-12T09:43:17.190809Z","shell.execute_reply":"2021-06-12T09:43:17.243129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(award_with_team.groupby(['awardSeason','playerName'])\\\n.agg({'divisionName':'count'}).rename(columns={'divisionName':'Award_count','awardSeason':'min_award_year','awardDate':'awardDate_min'})\\\n.reset_index()\\\n.sort_values('Award_count',ascending=False)\\\n.head(500)\\\n.pivot(index='playerName',columns='awardSeason',values='Award_count')\\\n.fillna(0))","metadata":{"execution":{"iopub.status.busy":"2021-06-12T09:43:55.647810Z","iopub.execute_input":"2021-06-12T09:43:55.648248Z","iopub.status.idle":"2021-06-12T09:43:57.165212Z","shell.execute_reply.started":"2021-06-12T09:43:55.648213Z","shell.execute_reply":"2021-06-12T09:43:57.163913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## >> In progress , Kindly upvote , If you like this notebooks","metadata":{}}]}