{"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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-09-04T21:54:51.394025Z","iopub.execute_input":"2022-09-04T21:54:51.394933Z","iopub.status.idle":"2022-09-04T21:54:51.410236Z","shell.execute_reply.started":"2022-09-04T21:54:51.394850Z","shell.execute_reply":"2022-09-04T21:54:51.408963Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Week Two!**\n\n**1 - Import race table and show first 5 rows**","metadata":{}},{"cell_type":"code","source":"race = pd.read_csv('/kaggle/input/big-data-derby-2022/nyra_race_table.csv')\nrace.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-09-04T21:54:51.419353Z","iopub.execute_input":"2022-09-04T21:54:51.419776Z","iopub.status.idle":"2022-09-04T21:54:51.445216Z","shell.execute_reply.started":"2022-09-04T21:54:51.419731Z","shell.execute_reply":"2022-09-04T21:54:51.444395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"race.info()","metadata":{"execution":{"iopub.status.busy":"2022-09-04T21:54:51.446582Z","iopub.execute_input":"2022-09-04T21:54:51.447120Z","iopub.status.idle":"2022-09-04T21:54:51.461650Z","shell.execute_reply.started":"2022-09-04T21:54:51.447087Z","shell.execute_reply":"2022-09-04T21:54:51.460303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**2 - apply EDA to race table with the following questions**\n \n***a) how many races we have in total in 2019?***","metadata":{}},{"cell_type":"code","source":"race['race_date'].dtype #Check race_date column dtype!","metadata":{"execution":{"iopub.status.busy":"2022-09-04T21:54:51.464487Z","iopub.execute_input":"2022-09-04T21:54:51.464827Z","iopub.status.idle":"2022-09-04T21:54:51.471920Z","shell.execute_reply.started":"2022-09-04T21:54:51.464797Z","shell.execute_reply":"2022-09-04T21:54:51.470757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"race.race_date = pd.to_datetime(race.race_date) #Convert race_date col. to datetime dtype","metadata":{"execution":{"iopub.status.busy":"2022-09-04T21:54:51.473851Z","iopub.execute_input":"2022-09-04T21:54:51.474576Z","iopub.status.idle":"2022-09-04T21:54:51.484148Z","shell.execute_reply.started":"2022-09-04T21:54:51.474533Z","shell.execute_reply":"2022-09-04T21:54:51.483191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#I Don't know the date range in race_date col. so ..\nrace.race_date.agg([min,max])","metadata":{"execution":{"iopub.status.busy":"2022-09-04T21:54:51.485614Z","iopub.execute_input":"2022-09-04T21:54:51.486227Z","iopub.status.idle":"2022-09-04T21:54:51.499787Z","shell.execute_reply.started":"2022-09-04T21:54:51.486168Z","shell.execute_reply":"2022-09-04T21:54:51.498625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*It is clear all races in race_table ran in 2019, so all rows/races belong to this period*","metadata":{}},{"cell_type":"code","source":"#Display df rows count\nrace.shape[0]","metadata":{"execution":{"iopub.status.busy":"2022-09-04T21:54:51.501277Z","iopub.execute_input":"2022-09-04T21:54:51.501697Z","iopub.status.idle":"2022-09-04T21:54:51.510876Z","shell.execute_reply.started":"2022-09-04T21:54:51.501666Z","shell.execute_reply":"2022-09-04T21:54:51.509751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## Another way in case date have more than 2019 year\nrace[race['race_date'].dt.year == 2019].count()","metadata":{"execution":{"iopub.status.busy":"2022-09-04T22:03:32.079893Z","iopub.execute_input":"2022-09-04T22:03:32.081410Z","iopub.status.idle":"2022-09-04T22:03:32.094376Z","shell.execute_reply.started":"2022-09-04T22:03:32.081367Z","shell.execute_reply":"2022-09-04T22:03:32.093043Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***b) Numerical Variables: what is the minimum/maximum/average/median (distance ,run_up_distance, and purse) of a race ?***","metadata":{}},{"cell_type":"markdown","source":"As shown in info method output that these columns are already int and ready for describe method.","metadata":{}},{"cell_type":"code","source":"race[['distance_id', 'run_up_distance', 'purse']].describe()","metadata":{"execution":{"iopub.status.busy":"2022-09-04T21:54:51.524570Z","iopub.execute_input":"2022-09-04T21:54:51.525093Z","iopub.status.idle":"2022-09-04T21:54:51.548112Z","shell.execute_reply.started":"2022-09-04T21:54:51.525062Z","shell.execute_reply":"2022-09-04T21:54:51.547054Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***c) Categorical Variables: how many races per (course_type, track_condition, and race_type)***","metadata":{}},{"cell_type":"code","source":"#Course_type race count\nrace['course_type'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-09-04T21:54:51.549526Z","iopub.execute_input":"2022-09-04T21:54:51.549837Z","iopub.status.idle":"2022-09-04T21:54:51.558373Z","shell.execute_reply.started":"2022-09-04T21:54:51.549809Z","shell.execute_reply":"2022-09-04T21:54:51.557154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#track_condition race count\nrace['track_condition'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-09-04T21:54:51.559756Z","iopub.execute_input":"2022-09-04T21:54:51.560578Z","iopub.status.idle":"2022-09-04T21:54:51.571702Z","shell.execute_reply.started":"2022-09-04T21:54:51.560545Z","shell.execute_reply":"2022-09-04T21:54:51.570458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#race_type count\nrace['race_type'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-09-04T21:54:51.572989Z","iopub.execute_input":"2022-09-04T21:54:51.574405Z","iopub.status.idle":"2022-09-04T21:54:51.584846Z","shell.execute_reply.started":"2022-09-04T21:54:51.574348Z","shell.execute_reply":"2022-09-04T21:54:51.583482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***d) Date Variable how many races played per week / month in 2019 ?***","metadata":{}},{"cell_type":"code","source":"#Count of races per month\nrace.groupby(race['race_date'].dt.month)['race_date'].count()","metadata":{"execution":{"iopub.status.busy":"2022-09-04T21:54:51.596285Z","iopub.execute_input":"2022-09-04T21:54:51.597216Z","iopub.status.idle":"2022-09-04T21:54:51.611185Z","shell.execute_reply.started":"2022-09-04T21:54:51.597168Z","shell.execute_reply":"2022-09-04T21:54:51.609968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Count of races per week\nrace.groupby(race['race_date'].dt.isocalendar().week)['race_date'].count()","metadata":{"execution":{"iopub.status.busy":"2022-09-04T21:56:04.366308Z","iopub.execute_input":"2022-09-04T21:56:04.366758Z","iopub.status.idle":"2022-09-04T21:56:04.380879Z","shell.execute_reply.started":"2022-09-04T21:56:04.366722Z","shell.execute_reply":"2022-09-04T21:56:04.379758Z"},"trusted":true},"execution_count":null,"outputs":[]}]}