{"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":"<div style=\"color:white;\n           display:fill;\n           border-radius:5px;\n           background-color:pink;\n           font-size:110%;\n           font-family:Verdana;\n           letter-spacing:0.5px\">\n<h1 style=\"text-align: center;\n           padding: 10px;\n              color:white\">\nMLB : EDA - Analysis the MLB\n\n</h1>\n</div>","metadata":{}},{"cell_type":"markdown","source":"![](https://upload.wikimedia.org/wikipedia/en/thumb/a/a6/Major_League_Baseball_logo.svg/1200px-Major_League_Baseball_logo.svg.png)","metadata":{}},{"cell_type":"markdown","source":"### MLB mean that Major League Baseball. \n### It's America and Canada's Baseball league. It's the dream league for all the baseball players!\n### I just try analysis that MLB teams and players","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport matplotlib.gridspec as gridspec\n\naward = pd.read_csv('../input/mlb-player-digital-engagement-forecasting/awards.csv')\nplayer = pd.read_csv('../input/mlb-player-digital-engagement-forecasting/players.csv')\nteam = pd.read_csv('../input/mlb-player-digital-engagement-forecasting/teams.csv')\n\nimport matplotlib.font_manager as fm\nfont = fm.FontProperties(fname='../input/staatfont/Staatliches-Regular.ttf')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-23T12:47:06.555135Z","iopub.execute_input":"2021-06-23T12:47:06.555537Z","iopub.status.idle":"2021-06-23T12:47:07.530936Z","shell.execute_reply.started":"2021-06-23T12:47:06.555455Z","shell.execute_reply":"2021-06-23T12:47:07.52989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"color:white;\n           display:fill;\n           border-radius:5px;\n           background-color:pink;\n           font-size:110%;\n           font-family:Verdana;\n           letter-spacing:0.5px\">\n<h1 style=\"text-align: center;\n           padding: 10px;\n              color:white\">\nMLB : Teams\n\n</h1>\n</div>","metadata":{}},{"cell_type":"markdown","source":"![](http://graphics.wsj.com/mlbteams/img/lede.jpg)","metadata":{}},{"cell_type":"code","source":"A_west = team[team['divisionName'] =='American League West'].name.to_list()\nA_east = team[team['divisionName'] =='American League East'].name.to_list()\nA_cen = team[team['divisionName'] =='American League Central'].name.to_list()\n\nN_west = team[team['divisionName'] =='National League West'].name.to_list()\nN_east = team[team['divisionName'] =='National League Central'].name.to_list()\nN_cen = team[team['divisionName'] =='National League East'].name.to_list()\n\nfig = plt.figure(figsize=(20,22))\n\nplt.text(s='American League West', x=0.25,y=0.9,va='center',ha='center',font=font,fontsize=30,alpha=0.3)\nfor i in range(len(A_west)):\n    plt.text(s=A_west[i],x=0.25,y=0.85 - 0.05*i, va='center',ha='center',font=font,fontsize=25)\nplt.text(s='American League East', x=0.25,y=0.6,va='center',ha='center',font=font,fontsize=30,alpha=0.3)\nfor i in range(len(A_cen)):\n    plt.text(s=A_cen[i],x=0.25,y=0.55 - 0.05*i, va='center',ha='center',font=font,fontsize=25)\nplt.text(s='American League Central', x=0.25,y=0.3,va='center',ha='center',font=font,fontsize=30,alpha=0.3)\nfor i in range(len(A_east)):\n    plt.text(s=A_east[i],x=0.25,y=0.25 - 0.05*i, va='center',ha='center',font=font,fontsize=25)\n    \nplt.text(s='National League West', x=0.75,y=0.9,va='center',ha='center',font=font,fontsize=30,alpha=0.3)\nfor i in range(len(N_west)):\n    plt.text(s=N_west[i],x=0.75,y=0.85 - 0.05*i, va='center',ha='center',font=font,fontsize=25)\nplt.text(s='National League Central', x=0.75,y=0.6,va='center',ha='center',font=font,fontsize=30,alpha=0.3)\nfor i in range(len(N_cen)):\n    plt.text(s=N_cen[i],x=0.75,y=0.55 - 0.05*i, va='center',ha='center',font=font,fontsize=25)\nplt.text(s='National League East', x=0.75,y=0.3,va='center',ha='center',font=font,fontsize=30,alpha=0.3)\nfor i in range(len(N_east)):\n    plt.text(s=N_east[i],x=0.75,y=0.25 - 0.05*i, va='center',ha='center',font=font,fontsize=25)\n\n\nplt.text(s='MLB League',x=0.5,y=0.95, font=font,fontsize=50,va='center',ha='center')\nplt.axvspan(0, 0.5, fc=\"lightcoral\", alpha=0.2)\nplt.axvspan(0.5, 1, fc=\"red\", alpha=0.2)\nplt.axis('off')\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-23T12:47:07.532543Z","iopub.execute_input":"2021-06-23T12:47:07.532941Z","iopub.status.idle":"2021-06-23T12:47:07.924571Z","shell.execute_reply.started":"2021-06-23T12:47:07.532889Z","shell.execute_reply":"2021-06-23T12:47:07.92358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### The MLB divide American League and National League and they divide three again that East, Central, West","metadata":{}},{"cell_type":"markdown","source":"<div style=\"color:white;\n           display:fill;\n           border-radius:5px;\n           background-color:pink;\n           font-size:110%;\n           font-family:Verdana;\n           letter-spacing:0.5px\">\n<h1 style=\"text-align: center;\n           padding: 10px;\n              color:white\">\nMLB : Player's Height\n\n</h1>\n</div>","metadata":{}},{"cell_type":"markdown","source":"![](https://upload.wikimedia.org/wikipedia/commons/thumb/8/88/Baseball_positions.svg/1200px-Baseball_positions.svg.png)","metadata":{}},{"cell_type":"markdown","source":"### Baseball have 10 position include DH. I want to compare player's height and weight.","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(20,10),facecolor='whitesmoke')\nax = plt.axes()\nsns.histplot(player['heightInches'],element ='poly',binwidth=1,color='pink',alpha=0.5)\nplt.text(s='Mean value', x=73,y=300,fontsize=15,va='center',ha='center',color='tomato')\nplt.axvline(73,linestyle ='--',color='tomato')\n\nplt.text(s='Median value', x=74,y=350,fontsize=15,va='center',ha='center',color='tomato')\nplt.axvline(74,linestyle ='--',color='tomato')\n\nplt.text(s=\"This is player's Average of height\",x = 66, y=400,font=font,fontsize=50)\n\nplt.gca().spines['right'].set_visible(False)\nplt.gca().spines['top'].set_visible(False)\nax.set(facecolor = \"whitesmoke\")\n\nplt.xticks(font=font, fontsize=18)\nplt.yticks(font=font, fontsize=18)\nplt.xlabel('Height', font = font, fontsize=20)\nplt.ylabel('')\n\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-23T12:47:07.926613Z","iopub.execute_input":"2021-06-23T12:47:07.927218Z","iopub.status.idle":"2021-06-23T12:47:08.248847Z","shell.execute_reply.started":"2021-06-23T12:47:07.927173Z","shell.execute_reply":"2021-06-23T12:47:08.248042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### The player's height \n### Mean value : 73\n### Median value : 74","metadata":{}},{"cell_type":"code","source":"player['primaryPositionName'] = player['primaryPositionName'].apply(lambda x: 'Outfielder' if x == 'Outfield' else x)\ntmp = pd.DataFrame(player['primaryPositionName'].value_counts())\ntmp.columns = ['counts']\n\ndef color_positive_green(val):\n    if val > 80:\n        color = 'black'\n    else:\n        color = 'pink'\n    return 'color: %s' % color\n  \ntmp.style.applymap(color_positive_green)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-23T12:47:08.250183Z","iopub.execute_input":"2021-06-23T12:47:08.250607Z","iopub.status.idle":"2021-06-23T12:47:08.297024Z","shell.execute_reply.started":"2021-06-23T12:47:08.250575Z","shell.execute_reply":"2021-06-23T12:47:08.296314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### I will compare without Designated Hitter and Infiled.","metadata":{}},{"cell_type":"markdown","source":"### We check player's average of height and weight. Now compare that with each position","metadata":{}},{"cell_type":"code","source":"mean_value = [player[player['primaryPositionName'] =='Pitcher']['heightInches'].describe()['mean'],\n             player[player['primaryPositionName'] =='Outfielder']['heightInches'].describe()['mean'],\n             player[player['primaryPositionName'] =='Catcher']['heightInches'].describe()['mean'],\n             player[player['primaryPositionName'] =='Second Base']['heightInches'].describe()['mean'],\n             player[player['primaryPositionName'] =='First Base']['heightInches'].describe()['mean'],\n             player[player['primaryPositionName'] =='Shortstop']['heightInches'].describe()['mean'],\n             player[player['primaryPositionName'] =='Third Base']['heightInches'].describe()['mean']]\n\nposition = ['Pitcher', 'Outfielder', 'Catcher', 'Second Base', 'First Base',\n       'Shortstop', 'Third Base']\n\nfig,axes = plt.subplots(nrows=7, ncols = 1,sharex=True,figsize=(20,25),facecolor='whitesmoke')\n\nsns.histplot(x= player[player['primaryPositionName'] =='Pitcher']['heightInches'],element ='poly',binwidth=1,ax=axes[0],color='pink')\naxes[0].text(s='Pitcher',x=80,y=200,font=font,fontsize=25,va='center',ha='center')\naxes[0].text(s='Mean value', x=mean_value[0],y=200,fontsize=15,va='center',ha='center',color='tomato')\naxes[0].axvline(mean_value[0],linestyle ='--',color='tomato')\naxes[0].set(facecolor = \"whitesmoke\")\n\nsns.histplot(x= player[player['primaryPositionName'] =='Outfielder']['heightInches'],element ='poly',binwidth=1,ax=axes[1],color='brown')\naxes[1].text(s='Outfielder',x=80,y=50,font=font,fontsize=25,va='center',ha='center')\naxes[1].text(s='Mean value', x=mean_value[1],y=50,fontsize=15,va='center',ha='center',color='tomato')\naxes[1].axvline(mean_value[1],linestyle ='--',color='tomato')\naxes[1].set(facecolor = \"whitesmoke\")\n\nsns.histplot(x= player[player['primaryPositionName'] =='Catcher']['heightInches'],element ='poly',binwidth=1,ax=axes[2],color='salmon')\naxes[2].text(s='Catcher',x=80,y=25,font=font,fontsize=25,va='center',ha='center')\naxes[2].text(s='Mean value', x=mean_value[2],y=25,fontsize=15,va='center',ha='center',color='tomato')\naxes[2].axvline(mean_value[2],linestyle ='--',color='tomato')\naxes[2].set(facecolor = \"whitesmoke\")\n\nsns.histplot(x= player[player['primaryPositionName'] =='Second Base']['heightInches'],element ='poly',binwidth=1,ax=axes[3],color='orange')\naxes[3].text(s='Second Base',x=80,y=20,font=font,fontsize=25,va='center',ha='center')\naxes[3].text(s='Mean value', x=mean_value[3],y=20,fontsize=15,va='center',ha='center',color='tomato')\naxes[3].axvline(mean_value[3],linestyle ='--',color='tomato')\naxes[3].set(facecolor = \"whitesmoke\")\n\nsns.histplot(x= player[player['primaryPositionName'] =='First Base']['heightInches'],element ='poly',binwidth=1,ax=axes[4],color='sienna')\naxes[4].text(s='First Base',x=80,y=15,font=font,fontsize=25,va='center',ha='center')\naxes[4].text(s='Mean value', x=mean_value[4],y=15,fontsize=15,va='center',ha='center',color='tomato')\naxes[4].axvline(mean_value[4],linestyle ='--',color='tomato')\naxes[4].set(facecolor = \"whitesmoke\")\n\nsns.histplot(x= player[player['primaryPositionName'] =='Shortstop']['heightInches'],element ='poly',binwidth=1,ax=axes[5],color='sandybrown')\naxes[5].text(s='Shortstop',x=80,y=15,font=font,fontsize=25,va='center',ha='center')\naxes[5].text(s='Mean value', x=mean_value[5],y=15,fontsize=15,va='center',ha='center',color='tomato')\naxes[5].axvline(mean_value[5],linestyle ='--',color='tomato')\naxes[5].set(facecolor = \"whitesmoke\")\n\nsns.histplot(x= player[player['primaryPositionName'] =='Third Base']['heightInches'],element ='poly',binwidth=1,ax=axes[6],color='peru')\naxes[6].text(s='Third Base',x=80,y=10,font=font,fontsize=25,va='center',ha='center')\naxes[6].text(s='Mean value', x=mean_value[6],y=10,fontsize=15,va='center',ha='center',color='tomato')\naxes[6].axvline(mean_value[6],linestyle ='--',color='tomato')\naxes[6].set(facecolor = \"whitesmoke\")\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-23T12:47:08.29802Z","iopub.execute_input":"2021-06-23T12:47:08.29842Z","iopub.status.idle":"2021-06-23T12:47:09.648895Z","shell.execute_reply.started":"2021-06-23T12:47:08.298392Z","shell.execute_reply":"2021-06-23T12:47:09.647952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### If you look this plot, We can know Pitcher's height is tallest.","metadata":{}},{"cell_type":"code","source":"mean_value = [player[player['primaryPositionName'] =='Pitcher']['heightInches'].describe()['mean'],\n             player[player['primaryPositionName'] =='Outfielder']['heightInches'].describe()['mean'],\n             player[player['primaryPositionName'] =='Catcher']['heightInches'].describe()['mean'],\n             player[player['primaryPositionName'] =='Second Base']['heightInches'].describe()['mean'],\n             player[player['primaryPositionName'] =='First Base']['heightInches'].describe()['mean'],\n             player[player['primaryPositionName'] =='Shortstop']['heightInches'].describe()['mean'],\n             player[player['primaryPositionName'] =='Third Base']['heightInches'].describe()['mean']]\n\nposition = ['Pitcher', 'Outfielder', 'Catcher', 'Second Base', 'First Base',\n       'Shortstop', 'Third Base']\n\nfig = plt.figure(figsize=(20,10),facecolor='whitesmoke')\nax = plt.axes()\nsns.histplot(player['heightInches'],element ='poly',binwidth=1,color='lightgreen',alpha=0.5)\n\nplt.text(s=\"This is player's Average of height by position\",x = 66, y=425,font=font,fontsize=50)\nplt.text(s=\"Just Compare Average, We can know that\",x = 66, y=410,font=font,fontsize=20)\nplt.text(s=\"Second Base < ShortStop < Thrid Base < Catcher < Out Fielder < First Base < Pitcher\",x = 66, y=395,font=font,fontsize=20)\n\nplt.gca().spines['right'].set_visible(False)\nplt.gca().spines['top'].set_visible(False)\nax.set(facecolor = \"whitesmoke\")\n\nplt.xticks(font=font, fontsize=18)\nplt.yticks(font=font, fontsize=18)\nplt.xlabel('Height', font = font, fontsize=20)\nplt.ylabel('')\n\nplt.text(s=position[0],x=mean_value[0],y=350,font=font,fontsize=20,va='center',ha='center',color='blue')\nplt.axvline(mean_value[0],linestyle ='--',color='blue')\n\nplt.text(s=position[1],x=mean_value[1],y=250,font=font,fontsize=20,va='center',ha='center',color='brown')\nplt.axvline(mean_value[1],linestyle ='--',color='brown')\n\nplt.text(s=position[2],x=mean_value[2],y=200,font=font,fontsize=20,va='center',ha='center',color='salmon')\nplt.axvline(mean_value[2],linestyle ='--',color='salmon')\n\nplt.text(s=position[3],x=mean_value[3],y=50,font=font,fontsize=20,va='center',ha='center',color='orange')\nplt.axvline(mean_value[3],linestyle ='--',color='orange')\n\nplt.text(s=position[4],x=mean_value[4],y=300,font=font,fontsize=20,va='center',ha='center',color='sienna')\nplt.axvline(mean_value[4],linestyle ='--',color='sienna')\n\nplt.text(s=position[5],x=mean_value[5],y=100,font=font,fontsize=20,va='center',ha='center',color='sandybrown')\nplt.axvline(mean_value[5],linestyle ='--',color='sandybrown')\n\nplt.text(s=position[6],x=mean_value[6],y=180,font=font,fontsize=20,va='center',ha='center',color='peru')\nplt.axvline(mean_value[6],linestyle ='--',color='peru')\n\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-23T12:47:09.650326Z","iopub.execute_input":"2021-06-23T12:47:09.650883Z","iopub.status.idle":"2021-06-23T12:47:09.966047Z","shell.execute_reply.started":"2021-06-23T12:47:09.650837Z","shell.execute_reply":"2021-06-23T12:47:09.965075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Pitcher is taller than other position. It have some reason.\n### If pitcter tall, It have some Nice effect.\n### First, Depending on the pitching form, the distance to the base is shortened.\n#### In fact, there will be no big difference in distance, but the hitter feel big difference.","metadata":{}},{"cell_type":"markdown","source":"![](https://inningace.com/wp-content/uploads/2020/07/pitching-cleats.jpg)","metadata":{}},{"cell_type":"markdown","source":"### Second, The ball starts from a high position.\n#### It's similarly with First reason. In hitter's visual range. It looks like that the ball dropped","metadata":{}},{"cell_type":"markdown","source":"![](https://images.wsj.net/im-317518?width=620&size=1.5980024968789013)","metadata":{}},{"cell_type":"markdown","source":"### If pitcher's height tall, Have effect in game - If you know another reason, Tell me plz!","metadata":{}},{"cell_type":"markdown","source":"<div style=\"color:white;\n           display:fill;\n           border-radius:5px;\n           background-color:pink;\n           font-size:110%;\n           font-family:Verdana;\n           letter-spacing:0.5px\">\n<h1 style=\"text-align: center;\n           padding: 10px;\n              color:white\">\nMLB : Player's Weight\n\n</h1>\n</div>","metadata":{}},{"cell_type":"markdown","source":"### Then, How about player's weight? Let's compare weight by position!","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(20,10),facecolor='whitesmoke')\nax = plt.axes()\nsns.histplot(player['weight'],element ='poly',binwidth=5,color='pink',alpha=0.5)\nplt.text(s='Mean / Median value', x=223,y=200,fontsize=15,va='center',ha='center',color='tomato')\nplt.axvline(210,linestyle ='--',color='tomato')\n\nplt.text(s=\"This is player's Average of weight\",x = 150, y=240,font=font,fontsize=50)\n\nplt.gca().spines['right'].set_visible(False)\nplt.gca().spines['top'].set_visible(False)\nax.set(facecolor = \"whitesmoke\")\n\nplt.xticks(font=font, fontsize=18)\nplt.yticks(font=font, fontsize=18)\nplt.xlabel('weight', font = font, fontsize=20)\nplt.ylabel('')\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-23T12:47:09.967452Z","iopub.execute_input":"2021-06-23T12:47:09.968051Z","iopub.status.idle":"2021-06-23T12:47:10.187078Z","shell.execute_reply.started":"2021-06-23T12:47:09.968008Z","shell.execute_reply":"2021-06-23T12:47:10.186041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### The player's weight\n### Mean / Median value : 210 (same)","metadata":{}},{"cell_type":"code","source":"mean_value2 = [player[player['primaryPositionName'] =='Pitcher']['weight'].describe()['mean'],\n             player[player['primaryPositionName'] =='Outfielder']['weight'].describe()['mean'],\n             player[player['primaryPositionName'] =='Catcher']['weight'].describe()['mean'],\n             player[player['primaryPositionName'] =='Second Base']['weight'].describe()['mean'],\n             player[player['primaryPositionName'] =='First Base']['weight'].describe()['mean'],\n             player[player['primaryPositionName'] =='Shortstop']['weight'].describe()['mean'],\n             player[player['primaryPositionName'] =='Third Base']['weight'].describe()['mean']]\n\nposition = ['Pitcher', 'Outfielder', 'Catcher', 'Second Base', 'First Base',\n       'Shortstop', 'Third Base']\n\nfig = plt.figure(figsize=(20,10),facecolor='whitesmoke')\nax = plt.axes()\nsns.histplot(player['weight'],element ='poly',binwidth=5,color='pink',alpha=0.5)\n\nplt.text(s=\"This is player's Average of weight\",x = 150, y=265,font=font,fontsize=50)\nplt.text(s=\"Compare player's weight\",x = 150, y=250,font=font,fontsize=20)\nplt.text(s=\"ShortStop < Second Base < Outfielder < Third Base < Picther < Catcher < First Base\",x = 150, y=240,font=font,fontsize=20)\n\n\nplt.gca().spines['right'].set_visible(False)\nplt.gca().spines['top'].set_visible(False)\nax.set(facecolor = \"whitesmoke\")\n\nplt.xticks(font=font, fontsize=18)\nplt.yticks(font=font, fontsize=18)\nplt.xlabel('weight', font = font, fontsize=20)\nplt.ylabel('')\n\nplt.text(s=position[0],x=mean_value2[0],y=160,font=font,fontsize=20,va='center',ha='center',color='blue')\nplt.axvline(mean_value2[0],linestyle ='--',color='blue')\n\nplt.text(s=position[1],x=mean_value2[1],y=100,font=font,fontsize=20,va='center',ha='center',color='brown')\nplt.axvline(mean_value2[1],linestyle ='--',color='brown')\n\nplt.text(s=position[2],x=mean_value2[2],y=190,font=font,fontsize=20,va='center',ha='center',color='salmon')\nplt.axvline(mean_value2[2],linestyle ='--',color='salmon')\n\nplt.text(s=position[3],x=mean_value2[3],y=70,font=font,fontsize=20,va='center',ha='center',color='orange')\nplt.axvline(mean_value2[3],linestyle ='--',color='orange')\n\nplt.text(s=position[4],x=mean_value2[4],y=220,font=font,fontsize=20,va='center',ha='center',color='sienna')\nplt.axvline(mean_value2[4],linestyle ='--',color='sienna')\n\nplt.text(s=position[5],x=mean_value2[5],y=50,font=font,fontsize=20,va='center',ha='center',color='sandybrown')\nplt.axvline(mean_value2[5],linestyle ='--',color='sandybrown')\n\nplt.text(s=position[6],x=mean_value2[6],y=120,font=font,fontsize=20,va='center',ha='center',color='peru')\nplt.axvline(mean_value2[6],linestyle ='--',color='peru')\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-23T12:47:10.189346Z","iopub.execute_input":"2021-06-23T12:47:10.18964Z","iopub.status.idle":"2021-06-23T12:47:10.48559Z","shell.execute_reply.started":"2021-06-23T12:47:10.18961Z","shell.execute_reply":"2021-06-23T12:47:10.484568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Surprisingly, The Weightest position is First Base !\n### Second Base and ShortStop are the lightest position\n### I think, Second base and ShortStop should be quick and agile. So they lighter than other position","metadata":{}},{"cell_type":"code","source":"player['Birth_year'] = player['DOB'].apply(lambda x : x.split('-')[0])\nplayer['Birth_year'] = pd.to_numeric(player['Birth_year'])\n\nweight_year = pd.DataFrame(player.groupby('Birth_year')['weight'].mean()).reset_index()\nfig = plt.figure(figsize=(20,13),facecolor='whitesmoke')\nax = plt.axes()\nplt.plot(weight_year['Birth_year'],weight_year['weight'],lw=8,color='pink')\nplt.gca().spines['right'].set_visible(False)\nplt.gca().spines['top'].set_visible(False)\nax.set(facecolor = \"whitesmoke\")\n\nplt.xticks(font=font, fontsize=18)\nplt.yticks(font=font, fontsize=18)\nplt.xlabel('Year - Birth of year', font = font, fontsize=20)\nplt.ylabel('Weight')\n\nplt.text(s='The relationship with player\\' Weight and age', x=1972, y=245,font=font, fontsize=50)\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-23T12:47:10.4871Z","iopub.execute_input":"2021-06-23T12:47:10.487392Z","iopub.status.idle":"2021-06-23T12:47:10.755839Z","shell.execute_reply.started":"2021-06-23T12:47:10.487363Z","shell.execute_reply":"2021-06-23T12:47:10.754954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### We can feel, player's age and weight have some relationship.","metadata":{}},{"cell_type":"code","source":"birth_position = pd.DataFrame(player.groupby('primaryPositionName')['Birth_year'].mean()).reset_index()\nbirth_position = birth_position.drop([1,3]).reset_index(drop=True)\nbirth_position['tmp_y'] =0\n\nfig = plt.figure(figsize=(15,10))\nplt.axhline(0,color='pink',lw=8,zorder=1)\nplt.scatter( x=birth_position['Birth_year'], y=birth_position['tmp_y'],s=300,zorder=2)\nplt.axis('off')\nplt.text(s='First Base : 1990.21', x=1990.1, y=0.01,font=font, fontsize=25)\nplt.text(s='Catcher : 1990.24', x=1990.2, y=-0.01,font=font, fontsize=25)\nplt.text(s='Third Base : 1990.73', x=1990.73, y=0.01,font=font, fontsize=25)\nplt.text(s='Pitcher : 1991.14', x=1991., y=-0.01,font=font, fontsize=25)\nplt.text(s='Second Base : 1991.43', x=1991.43, y=0.01,font=font, fontsize=25)\nplt.text(s='Outfielder : 1991.46', x=1991.46, y=-0.01,font=font, fontsize=25)\nplt.text(s='Shortstop : 1992.34', x=1992.2, y=-0.01,font=font, fontsize=25)\n\nplt.text(s='The average of Birth year', x=1990.15, y=0.03,font=font, fontsize=50)\n\n\nfig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-23T12:47:10.757032Z","iopub.execute_input":"2021-06-23T12:47:10.757469Z","iopub.status.idle":"2021-06-23T12:47:10.905211Z","shell.execute_reply.started":"2021-06-23T12:47:10.757429Z","shell.execute_reply":"2021-06-23T12:47:10.904149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### If you look this plot, We can know, First base and Catcher position are more Beteran than other position.\n### So I think, they are weighter than other position.","metadata":{}},{"cell_type":"markdown","source":"![](http://www.baseballbytheyard.com/wp-content/uploads/2014/04/628x471m.jpg)","metadata":{}},{"cell_type":"code","source":"def highlight_max(s):\n    '''\n    highlight the maximum in a Series yellow.\n    '''\n    is_max = s == s.max()\n    return ['background-color: yellow' if v else '' for v in is_max]\n\ncom_value = pd.concat([pd.DataFrame(mean_value),pd.DataFrame(mean_value2)],axis=1)\ncom_value['position'] = position\ncom_value.columns =['Height','Weight','Position']\ncom_value = com_value[['Position','Height','Weight']]\ncom_value.set_index('Position').style.apply(highlight_max)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-23T12:47:10.906477Z","iopub.execute_input":"2021-06-23T12:47:10.906827Z","iopub.status.idle":"2021-06-23T12:47:10.929876Z","shell.execute_reply.started":"2021-06-23T12:47:10.906793Z","shell.execute_reply":"2021-06-23T12:47:10.928534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"color:white;\n           display:fill;\n           border-radius:5px;\n           background-color:pink;\n           font-size:110%;\n           font-family:Verdana;\n           letter-spacing:0.5px\">\n<h1 style=\"text-align: center;\n           padding: 10px;\n              color:white\">\nMLB : Awarded player\n\n</h1>\n</div>","metadata":{}},{"cell_type":"code","source":"award_player = pd.DataFrame(award['playerName'].value_counts()[:10]).reset_index()\nfig = plt.figure(figsize=(23,13),facecolor='whitesmoke')\nsns.barplot(data= award_player, y='index',x='playerName',palette='dark:salmon_r',alpha=0.3)\nplt.axis('off')\n\nplt.text(s=\"awarded Player - Counts\",x=0, y=-0.8,font=font,fontsize=50)\n\nfor i in range(len(award_player)):\n    plt.text(s=award_player['index'][i],x=award_player['playerName'][i]-1,y=i,va='center',ha='right',font=font,fontsize=30)\n    plt.text(s=award_player['playerName'][i],x=award_player['playerName'][i]+1,y=i,va='center',ha='left',font=font,fontsize=30)\n\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-23T12:47:10.931402Z","iopub.execute_input":"2021-06-23T12:47:10.931888Z","iopub.status.idle":"2021-06-23T12:47:11.175718Z","shell.execute_reply.started":"2021-06-23T12:47:10.931842Z","shell.execute_reply":"2021-06-23T12:47:11.174733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Albert Pujols is best player by awarded counts","metadata":{}},{"cell_type":"markdown","source":"<div style=\"color:white;\n           display:fill;\n           border-radius:5px;\n           background-color:pink;\n           font-size:110%;\n           font-family:Verdana;\n           letter-spacing:0.5px\">\n<h1 style=\"text-align: center;\n           padding: 10px;\n              color:white\">\nThank you to watch this work !\n\n</h1>\n</div>","metadata":{}},{"cell_type":"markdown","source":"![](https://media2.giphy.com/media/4V0mAzoxs73gSl2wxz/200.gif)","metadata":{}},{"cell_type":"markdown","source":"### Thank you @ PC Jimmmy\n### Your comments are very important and helpful to me.","metadata":{}}]}