{"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":"# NFL Big Data Bowl 2022: Warmup\n#### This notebook I am using with emphasis on my warm up with the data and Pandas. Rather than produce valuable insight for the competition.","metadata":{}},{"cell_type":"code","source":"import pandas as pd\n\nFOLDER_PATH = '../input/nfl-big-data-bowl-2022/'\ndf = pd.read_csv(FOLDER_PATH + 'players.csv')","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:45.990318Z","iopub.execute_input":"2021-10-11T22:03:45.991233Z","iopub.status.idle":"2021-10-11T22:03:46.054862Z","shell.execute_reply.started":"2021-10-11T22:03:45.991105Z","shell.execute_reply":"2021-10-11T22:03:46.053523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head(2)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.057137Z","iopub.execute_input":"2021-10-11T22:03:46.057576Z","iopub.status.idle":"2021-10-11T22:03:46.089212Z","shell.execute_reply.started":"2021-10-11T22:03:46.057529Z","shell.execute_reply":"2021-10-11T22:03:46.087993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.090915Z","iopub.execute_input":"2021-10-11T22:03:46.091262Z","iopub.status.idle":"2021-10-11T22:03:46.099549Z","shell.execute_reply.started":"2021-10-11T22:03:46.091221Z","shell.execute_reply":"2021-10-11T22:03:46.098266Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.102388Z","iopub.execute_input":"2021-10-11T22:03:46.102755Z","iopub.status.idle":"2021-10-11T22:03:46.146478Z","shell.execute_reply.started":"2021-10-11T22:03:46.102714Z","shell.execute_reply":"2021-10-11T22:03:46.145754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### There missing values in columns \"birthDate\" and \"collegeName\". I will look for this data on Wikipedia.","metadata":{}},{"cell_type":"code","source":"df[df[\"birthDate\"].isnull()]","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.148484Z","iopub.execute_input":"2021-10-11T22:03:46.149117Z","iopub.status.idle":"2021-10-11T22:03:46.167554Z","shell.execute_reply.started":"2021-10-11T22:03:46.149072Z","shell.execute_reply":"2021-10-11T22:03:46.166731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# https://en.wikipedia.org/wiki/Raekwon_Davis\ndf.iat[60,3] = \"1997-06-10\"\n# https://en.wikipedia.org/wiki/Bravvion_Roy\ndf.iat[111,3] = \"1996-10-18\"\n# https://en.wikipedia.org/wiki/Bravvion_Roy\ndf.iat[258,3] = \"1996-10-18\"\n# https://en.wikipedia.org/wiki/Antoine_Brooks\ndf.iat[322,3] = \"1997-10-28\"\n# https://en.wikipedia.org/wiki/Mike_Danna\ndf.iat[452,3] = \"1997-12-04\"\n# https://en.wikipedia.org/wiki/Bryce_Hall_(American_football)\ndf.iat[501,3] = \"1997-11-05\"\n# https://en.wikipedia.org/wiki/Carter_Coughlin\ndf.iat[547,3] = \"1997-07-21\"\n# https://en.wikipedia.org/wiki/Hunter_Niswander\ndf.iat[585,3] = \"1994-11-26\"\n# https://en.wikipedia.org/wiki/James_Smith-Williams\ndf.iat[615,3] = \"1997-07-29\"\n# https://en.wikipedia.org/wiki/Jameson_Houston\ndf.iat[650,3] = \"1996-06-30\"\n# https://en.wikipedia.org/wiki/Jameson_Houston\ndf.iat[658,3] = \"1999-03-03\"\n# https://en.wikipedia.org/wiki/Derrek_Tuszka\ndf.iat[750,3] = \"1997-08-17\"\n# https://en.wikipedia.org/wiki/Chris_Claybrooks\ndf.iat[881,3] = \"1998-07-17\"\n# https://en.wikipedia.org/wiki/Rashard_Lawrence\ndf.iat[986,3] = \"1998-08-27\"\n# https://en.wikipedia.org/wiki/Taylor_Russolino\ndf.iat[1284,3] = \"1989-05-23\"\n# https://en.wikipedia.org/wiki/Bradlee_Anae\ndf.iat[1693,3] = \"1998-10-17\"\n# https://en.wikipedia.org/wiki/Trevon_Diggs Based on Wikipedia year of birth is 1998 or 1997.\n# So I checked on ESPN\n# https://www.espn.com/nfl/player/_/id/4040966/trevon-diggs\ndf.iat[1799,3] = \"1997-09-20\"","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.169091Z","iopub.execute_input":"2021-10-11T22:03:46.169572Z","iopub.status.idle":"2021-10-11T22:03:46.183630Z","shell.execute_reply.started":"2021-10-11T22:03:46.169524Z","shell.execute_reply":"2021-10-11T22:03:46.182953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[df[\"collegeName\"].isnull()]","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.185289Z","iopub.execute_input":"2021-10-11T22:03:46.185805Z","iopub.status.idle":"2021-10-11T22:03:46.210528Z","shell.execute_reply.started":"2021-10-11T22:03:46.185763Z","shell.execute_reply":"2021-10-11T22:03:46.209475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# https://en.wikipedia.org/wiki/Keandre_Jones\ndf.iat[258,4] = \"Maryland Terrapins\"\n# https://en.wikipedia.org/wiki/Bryce_Hall_(American_football)\ndf.iat[501,4] = \"Virginia\"\n# https://en.wikipedia.org/wiki/Hunter_Niswander\ndf.iat[585,4] = \"Northwestern\"\n# https://en.wikipedia.org/wiki/Jameson_Houston\ndf.iat[650,4] = \"Baylor\"\n# https://en.wikipedia.org/wiki/Jameson_Houston\ndf.iat[650,4] = \"Baylor\"\n# https://en.wikipedia.org/wiki/Taylor_Russolino\ndf.iat[1284,4] = \"Millsaps\"\n# https://en.wikipedia.org/wiki/Javon_Leake\ndf.iat[1441,4] = \" Maryland\"\n# https://en.wikipedia.org/wiki/Rodney_Smith_(running_back)\ndf.iat[1564,4] = \"Minnesota\"\n# https://en.wikipedia.org/wiki/Brandon_Wright\ndf.iat[1823,4] = \"Georgia State\"","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.212026Z","iopub.execute_input":"2021-10-11T22:03:46.212609Z","iopub.status.idle":"2021-10-11T22:03:46.222931Z","shell.execute_reply.started":"2021-10-11T22:03:46.212574Z","shell.execute_reply":"2021-10-11T22:03:46.222024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.height.unique()","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.224419Z","iopub.execute_input":"2021-10-11T22:03:46.224727Z","iopub.status.idle":"2021-10-11T22:03:46.238955Z","shell.execute_reply.started":"2021-10-11T22:03:46.224690Z","shell.execute_reply":"2021-10-11T22:03:46.238265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Height appear in two different ways. Converting them all into centimeters.","metadata":{}},{"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":"2021-10-11T22:03:46.241579Z","iopub.execute_input":"2021-10-11T22:03:46.242177Z","iopub.status.idle":"2021-10-11T22:03:46.249402Z","shell.execute_reply.started":"2021-10-11T22:03:46.242146Z","shell.execute_reply":"2021-10-11T22:03:46.248770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"height_cm\"] = df[\"height\"].replace(height_dict)\ndf[\"weight_kg\"] = df[\"weight\"] * 0.4535924\ndf[\"weight_kg\"] = df[\"weight_kg\"].astype(int)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.250470Z","iopub.execute_input":"2021-10-11T22:03:46.250894Z","iopub.status.idle":"2021-10-11T22:03:46.287678Z","shell.execute_reply.started":"2021-10-11T22:03:46.250856Z","shell.execute_reply":"2021-10-11T22:03:46.286680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Body mass index\ndf[\"bmi\"] = df[\"weight_kg\"] / ((df[\"height_cm\"]/100)* (df[\"height_cm\"]/100))\ndf[\"bmi\"] = df[\"bmi\"].round(1)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.289352Z","iopub.execute_input":"2021-10-11T22:03:46.289778Z","iopub.status.idle":"2021-10-11T22:03:46.299854Z","shell.execute_reply.started":"2021-10-11T22:03:46.289734Z","shell.execute_reply":"2021-10-11T22:03:46.298730Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['DateTime'] = pd.to_datetime(df['birthDate'],errors='coerce')\ndf[\"dayofweek\"] = df[\"DateTime\"].dt.day_name()\ndf[\"month\"] =  df[\"DateTime\"].dt.month\ndf[\"year\"] = df[\"DateTime\"].dt.year\nCURRENT_YEAR = 2021\ndf[\"age\"] = CURRENT_YEAR - df[\"year\"]","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.301578Z","iopub.execute_input":"2021-10-11T22:03:46.302446Z","iopub.status.idle":"2021-10-11T22:03:46.322445Z","shell.execute_reply.started":"2021-10-11T22:03:46.302399Z","shell.execute_reply":"2021-10-11T22:03:46.321601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"position_dict ={\n\"QB\": \"Quarterback\",\n\n\"RB\": \"Running Back\",\n\n\"FB\": \"Fullback\",\n\n\"WR\": \"Wide Receiver\",\n\n\"TE\": \"Tight End\",\n\n\"OL\": \"Offensive Lineman\",\n\n\"C\": \"Center\",\n\n\"G\": \"Guard\",\n\n\"LG\": \"Left Guard\",\n\n\"RG\": \"Right Guard\",\n\n\"T\": \"Tackle\",\n\"LT\": \"Left Tackle\",\n\n\"RT\": \"Right Tackle\",\n\n\"K\": \"Kicker\",\n\n\"KR\": \"Kick Returner\",\n\n\"DL\": \"Defensive Lineman\",\n\n\"DE\": \"Defensive End\",\n\n\"DT\": \"Defensive Tackle\",\n\n\"NT\": \"Nose Tackle\",\n\n\"LB\": \"Linebacker\",\n\n\"ILB\": \"Inside Linebacker\",\n\n\"OLB\": \"Outside Linebacker\",\n\n\"MLB\": \"Middle Linebacker\",\n\n\"DB\": \"Defensive Back\",\n\n\"CB\": \"Cornerback\",\n\n\"FS\": \"Free Safety\",\n\n\"SS\": \"Strong Safety\",\n\n\"S\": \"Safety\",\n\n\"P\": \"Punter\",\n\n\"PR\": \"Punt Returner\"\n}","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.323795Z","iopub.execute_input":"2021-10-11T22:03:46.324196Z","iopub.status.idle":"2021-10-11T22:03:46.333809Z","shell.execute_reply.started":"2021-10-11T22:03:46.324165Z","shell.execute_reply":"2021-10-11T22:03:46.332435Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"position_name\"] = df[\"Position\"].replace(position_dict)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.335029Z","iopub.execute_input":"2021-10-11T22:03:46.335351Z","iopub.status.idle":"2021-10-11T22:03:46.363004Z","shell.execute_reply.started":"2021-10-11T22:03:46.335316Z","shell.execute_reply":"2021-10-11T22:03:46.361867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.tail(2)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.364471Z","iopub.execute_input":"2021-10-11T22:03:46.364999Z","iopub.status.idle":"2021-10-11T22:03:46.389947Z","shell.execute_reply.started":"2021-10-11T22:03:46.364955Z","shell.execute_reply":"2021-10-11T22:03:46.387454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.weight_kg.describe().round(1)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.392109Z","iopub.execute_input":"2021-10-11T22:03:46.392827Z","iopub.status.idle":"2021-10-11T22:03:46.409218Z","shell.execute_reply.started":"2021-10-11T22:03:46.392779Z","shell.execute_reply":"2021-10-11T22:03:46.408271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.height_cm.describe().round(1)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.410348Z","iopub.execute_input":"2021-10-11T22:03:46.410844Z","iopub.status.idle":"2021-10-11T22:03:46.423012Z","shell.execute_reply.started":"2021-10-11T22:03:46.410804Z","shell.execute_reply":"2021-10-11T22:03:46.422003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.bmi.describe().round(1)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.424614Z","iopub.execute_input":"2021-10-11T22:03:46.425195Z","iopub.status.idle":"2021-10-11T22:03:46.443189Z","shell.execute_reply.started":"2021-10-11T22:03:46.425162Z","shell.execute_reply":"2021-10-11T22:03:46.442389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.groupby('Position')['bmi'].mean().round(1)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.444420Z","iopub.execute_input":"2021-10-11T22:03:46.445095Z","iopub.status.idle":"2021-10-11T22:03:46.462377Z","shell.execute_reply.started":"2021-10-11T22:03:46.445061Z","shell.execute_reply":"2021-10-11T22:03:46.461113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.groupby('Position')['height_cm'].mean().round(1)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.464399Z","iopub.execute_input":"2021-10-11T22:03:46.465143Z","iopub.status.idle":"2021-10-11T22:03:46.479817Z","shell.execute_reply.started":"2021-10-11T22:03:46.465094Z","shell.execute_reply":"2021-10-11T22:03:46.478947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.age.value_counts().round(1)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.481031Z","iopub.execute_input":"2021-10-11T22:03:46.481854Z","iopub.status.idle":"2021-10-11T22:03:46.494479Z","shell.execute_reply.started":"2021-10-11T22:03:46.481742Z","shell.execute_reply":"2021-10-11T22:03:46.492178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.month.value_counts().round(1)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T22:03:46.496317Z","iopub.execute_input":"2021-10-11T22:03:46.497439Z","iopub.status.idle":"2021-10-11T22:03:46.511704Z","shell.execute_reply.started":"2021-10-11T22:03:46.497371Z","shell.execute_reply":"2021-10-11T22:03:46.510424Z"},"trusted":true},"execution_count":null,"outputs":[]}]}