{"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\n\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-01-06T00:56:47.171864Z","iopub.execute_input":"2022-01-06T00:56:47.172829Z","iopub.status.idle":"2022-01-06T00:56:47.189729Z","shell.execute_reply.started":"2022-01-06T00:56:47.172778Z","shell.execute_reply":"2022-01-06T00:56:47.188291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players_df = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2022/players.csv')\nplayers_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-06T00:56:47.192257Z","iopub.execute_input":"2022-01-06T00:56:47.192729Z","iopub.status.idle":"2022-01-06T00:56:47.217955Z","shell.execute_reply.started":"2022-01-06T00:56:47.192695Z","shell.execute_reply":"2022-01-06T00:56:47.217023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players_df['Position'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-01-06T00:56:47.219010Z","iopub.execute_input":"2022-01-06T00:56:47.219299Z","iopub.status.idle":"2022-01-06T00:56:47.231330Z","shell.execute_reply.started":"2022-01-06T00:56:47.219268Z","shell.execute_reply":"2022-01-06T00:56:47.230166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players_df = players_df[players_df.Position != \"WR\"]\nplayers_df = players_df[players_df.Position != \"CB\"]\nplayers_df = players_df[players_df.Position != \"DE\"]\nplayers_df = players_df[players_df.Position != \"OLB\"]\nplayers_df = players_df[players_df.Position != \"TE\"]\nplayers_df = players_df[players_df.Position != \"T\"]\nplayers_df = players_df[players_df.Position != \"RB\"]\nplayers_df = players_df[players_df.Position != \"DT\"]\nplayers_df = players_df[players_df.Position != \"ILB\"]\nplayers_df = players_df[players_df.Position != \"FS\"]\nplayers_df = players_df[players_df.Position != \"SS\"]\nplayers_df = players_df[players_df.Position != \"C\"]\nplayers_df = players_df[players_df.Position != \"NT\"]\nplayers_df = players_df[players_df.Position != \"DB\"]\nplayers_df = players_df[players_df.Position != \"LB\"]\nplayers_df = players_df[players_df.Position != \"MLB\"]\nplayers_df = players_df[players_df.Position != \"FB\"]\nplayers_df = players_df[players_df.Position != \"OT\"]\nplayers_df = players_df[players_df.Position != \"QB\"]\nplayers_df = players_df[players_df.Position != \"S\"]\nplayers_df = players_df[players_df.Position != \"OG\"]\nplayers_df = players_df[players_df.Position != \"HB\"]\n\n# # K H P LS G KR/PR\n# players_df['Position'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-01-06T00:56:47.234178Z","iopub.execute_input":"2022-01-06T00:56:47.234587Z","iopub.status.idle":"2022-01-06T00:56:47.266730Z","shell.execute_reply.started":"2022-01-06T00:56:47.234553Z","shell.execute_reply":"2022-01-06T00:56:47.265722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"height_dict = {\n    \"5-10\": 178,\n    \"5-11\": 180,\n    \"5-6\": 168,\n    \"5-7\": 170,\n    \"5-8\": 173,\n    \"5-9\": 175,\n    \"6-0\": 183,\n    \"6-1\": 185,\n    \"6-2\": 188,\n    \"6-3\": 190,\n    \"6-4\": 193,\n    \"6-5\": 196,\n    \"6-6\": 198,\n    \"6-7\": 201,\n    \"6-8\": 203,\n    \"6-9\": 206,\n    \"66\": 168,\n    \"67\": 170,\n    \"68\": 173,\n    \"69\": 175,\n    \"70\": 178,\n    \"71\": 180,\n    \"72\": 183,\n    \"73\": 185,\n    \"74\": 188,\n    \"75\": 191,\n    \"76\": 193,\n    \"77\": 196,\n    \"78\": 198,\n    \"79\": 201\n}","metadata":{"execution":{"iopub.status.busy":"2022-01-06T00:56:47.268209Z","iopub.execute_input":"2022-01-06T00:56:47.268446Z","iopub.status.idle":"2022-01-06T00:56:47.276002Z","shell.execute_reply.started":"2022-01-06T00:56:47.268419Z","shell.execute_reply":"2022-01-06T00:56:47.275022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players_df[\"height_cm\"] = players_df[\"height\"].replace(height_dict)\nplayers_df[\"height_m2\"] = players_df[\"height_cm\"]*0.01*players_df[\"height_cm\"]*0.01\nplayers_df[\"weight_kg\"] = players_df[\"weight\"]*0.45359237\nplayers_df","metadata":{"execution":{"iopub.status.busy":"2022-01-06T00:56:47.278192Z","iopub.execute_input":"2022-01-06T00:56:47.278572Z","iopub.status.idle":"2022-01-06T00:56:47.315311Z","shell.execute_reply.started":"2022-01-06T00:56:47.278540Z","shell.execute_reply":"2022-01-06T00:56:47.314245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.express as px\nfig = px.box(players_df,x=\"Position\",y=\"height_cm\",points = \"all\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-06T00:56:47.316778Z","iopub.execute_input":"2022-01-06T00:56:47.317057Z","iopub.status.idle":"2022-01-06T00:56:47.392690Z","shell.execute_reply.started":"2022-01-06T00:56:47.317001Z","shell.execute_reply":"2022-01-06T00:56:47.391511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.box(players_df,x=\"Position\",y=\"weight_kg\", points = \"all\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-06T00:56:47.394495Z","iopub.execute_input":"2022-01-06T00:56:47.394920Z","iopub.status.idle":"2022-01-06T00:56:47.470578Z","shell.execute_reply.started":"2022-01-06T00:56:47.394872Z","shell.execute_reply":"2022-01-06T00:56:47.469598Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players_df[\"bmi\"] = players_df[\"weight_kg\"]/players_df[\"height_m2\"]\nfig = px.box(players_df,x=\"Position\",y=\"bmi\", points = \"all\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-06T00:56:47.472396Z","iopub.execute_input":"2022-01-06T00:56:47.472943Z","iopub.status.idle":"2022-01-06T00:56:47.546463Z","shell.execute_reply.started":"2022-01-06T00:56:47.472898Z","shell.execute_reply":"2022-01-06T00:56:47.545479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"players_df[\"nomalized_bmi\"]=(players_df[\"bmi\"]-players_df[\"bmi\"].min())/(players_df[\"bmi\"].max()-players_df[\"bmi\"].min())*100\nplayers_df","metadata":{"execution":{"iopub.status.busy":"2022-01-06T00:56:47.550057Z","iopub.execute_input":"2022-01-06T00:56:47.550413Z","iopub.status.idle":"2022-01-06T00:56:47.581059Z","shell.execute_reply.started":"2022-01-06T00:56:47.550368Z","shell.execute_reply":"2022-01-06T00:56:47.579930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nimport random\ncolor_dict = {\n    \"G\": 'red',\n    \"K\": 'limegreen',\n    \"P\": 'royalblue',\n    \"LS\": 'purple',\n    \"WR\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"CB\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"DE\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"OLB\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"TE\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"T\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"RB\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"DT\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"ILB\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"FS\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"SS\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"C\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"NT\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"DB\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"MLB\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"FB\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"OT\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"QB\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"S\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"OG\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"HB\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]),\n    \"LB\": \"#\"+''.join([random.choice('0123456789ABCDEF') for j in range(6)])\n}\nplayers_df[\"color\"] = players_df[\"Position\"].replace(color_dict)\nplayers_df\n","metadata":{"execution":{"iopub.status.busy":"2022-01-06T00:56:47.582857Z","iopub.execute_input":"2022-01-06T00:56:47.583719Z","iopub.status.idle":"2022-01-06T00:56:47.635921Z","shell.execute_reply.started":"2022-01-06T00:56:47.583674Z","shell.execute_reply":"2022-01-06T00:56:47.635138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nfig = plt.figure(figsize=(10, 6))\nplt.scatter(players_df[\"height_cm\"], players_df[\"weight_kg\"],c=players_df[\"color\"], s=players_df[\"nomalized_bmi\"],alpha=0.5)\nplt.xlabel('height_cm')\nplt.ylabel('weight_kg')\n\n\nimport matplotlib.patches as mpatches\nfrom collections import OrderedDict\n# plot the color description bar\ncolorlist = zip(players_df['Position'], players_df['color'])\ncolorlist = list(OrderedDict.fromkeys(colorlist))\nhandles = [mpatches.Patch(color=colour, label=label) for label, colour in colorlist]\ncolorlist = [i[0] for i in colorlist]\nplt.legend(handles, colorlist, bbox_to_anchor=(1.1, 1))\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-01-06T00:56:57.864133Z","iopub.execute_input":"2022-01-06T00:56:57.864564Z","iopub.status.idle":"2022-01-06T00:56:58.089278Z","shell.execute_reply.started":"2022-01-06T00:56:57.864533Z","shell.execute_reply":"2022-01-06T00:56:58.088241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}