{"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-03T19:28:51.295353Z","iopub.execute_input":"2022-09-03T19:28:51.296419Z","iopub.status.idle":"2022-09-03T19:28:51.337431Z","shell.execute_reply.started":"2022-09-03T19:28:51.296255Z","shell.execute_reply":"2022-09-03T19:28:51.336062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Introductin\nThere are many factors affecting Sports that involve animals, on of the imporatant factor is injury prevention.\nThe goal of this competition is to analyze horse racing tactics, drafting strategies, and path efficiency.","metadata":{}},{"cell_type":"code","source":"start_table = pd.read_csv('/kaggle/input/big-data-derby-2022/nyra_start_table.csv')\nstart_table.head()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T19:47:36.856089Z","iopub.execute_input":"2022-09-03T19:47:36.856622Z","iopub.status.idle":"2022-09-03T19:47:36.893066Z","shell.execute_reply.started":"2022-09-03T19:47:36.856580Z","shell.execute_reply":"2022-09-03T19:47:36.891874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"start_table.info()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T20:12:29.596880Z","iopub.execute_input":"2022-09-03T20:12:29.597439Z","iopub.status.idle":"2022-09-03T20:12:29.623148Z","shell.execute_reply.started":"2022-09-03T20:12:29.597391Z","shell.execute_reply":"2022-09-03T20:12:29.621634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"start_table['race_date'] = pd.to_datetime(start_table['race_date'])\nstart_table.info()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T20:18:00.982757Z","iopub.execute_input":"2022-09-03T20:18:00.984003Z","iopub.status.idle":"2022-09-03T20:18:01.027410Z","shell.execute_reply.started":"2022-09-03T20:18:00.983950Z","shell.execute_reply":"2022-09-03T20:18:01.026088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"race_table = pd.read_csv('/kaggle/input/big-data-derby-2022/nyra_race_table.csv')\nrace_table['race_date'] = pd.to_datetime(race_table['race_date'])\nrace_table.head()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T20:19:52.122890Z","iopub.execute_input":"2022-09-03T20:19:52.124010Z","iopub.status.idle":"2022-09-03T20:19:52.160372Z","shell.execute_reply.started":"2022-09-03T20:19:52.123955Z","shell.execute_reply":"2022-09-03T20:19:52.158709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"race_table.info()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T20:19:56.210796Z","iopub.execute_input":"2022-09-03T20:19:56.211300Z","iopub.status.idle":"2022-09-03T20:19:56.229739Z","shell.execute_reply.started":"2022-09-03T20:19:56.211257Z","shell.execute_reply":"2022-09-03T20:19:56.228214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tracking_table = pd.read_csv('/kaggle/input/big-data-derby-2022/nyra_tracking_table.csv')\ntracking_table['race_date'] = pd.to_datetime(tracking_table['race_date'])\ntracking_table.head()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T20:20:37.362913Z","iopub.execute_input":"2022-09-03T20:20:37.363426Z","iopub.status.idle":"2022-09-03T20:20:43.736542Z","shell.execute_reply.started":"2022-09-03T20:20:37.363381Z","shell.execute_reply":"2022-09-03T20:20:43.735559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tracking_table.info()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T20:20:51.111552Z","iopub.execute_input":"2022-09-03T20:20:51.112512Z","iopub.status.idle":"2022-09-03T20:20:51.126900Z","shell.execute_reply.started":"2022-09-03T20:20:51.112458Z","shell.execute_reply":"2022-09-03T20:20:51.125419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"complete_2019 = pd.read_csv('/kaggle/input/big-data-derby-2022/nyra_2019_complete.csv')\ncomplete_2019.head()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T20:23:22.278158Z","iopub.execute_input":"2022-09-03T20:23:22.278706Z","iopub.status.idle":"2022-09-03T20:23:39.898451Z","shell.execute_reply.started":"2022-09-03T20:23:22.278666Z","shell.execute_reply":"2022-09-03T20:23:39.896835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"complete_2019['race_date'] = pd.to_datetime(complete_2019['race_date'])\ncomplete_2019.info()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T20:25:18.107536Z","iopub.execute_input":"2022-09-03T20:25:18.108110Z","iopub.status.idle":"2022-09-03T20:25:19.670697Z","shell.execute_reply.started":"2022-09-03T20:25:18.108070Z","shell.execute_reply":"2022-09-03T20:25:19.669202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## **How many races have in total in 2019?**","metadata":{}},{"cell_type":"code","source":"race_table.race_date.count()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T21:18:16.804094Z","iopub.execute_input":"2022-09-03T21:18:16.805025Z","iopub.status.idle":"2022-09-03T21:18:16.813011Z","shell.execute_reply.started":"2022-09-03T21:18:16.804973Z","shell.execute_reply":"2022-09-03T21:18:16.811984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## **what is the minimum/maximum/average/median (distance ,run_up_distance, and purse) of a race ?**","metadata":{}},{"cell_type":"code","source":"race_table.head()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T21:01:36.152147Z","iopub.execute_input":"2022-09-03T21:01:36.152735Z","iopub.status.idle":"2022-09-03T21:01:36.170737Z","shell.execute_reply.started":"2022-09-03T21:01:36.152684Z","shell.execute_reply":"2022-09-03T21:01:36.169438Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#distance \nrace_table['distance_id'].describe()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T21:07:45.762457Z","iopub.execute_input":"2022-09-03T21:07:45.763506Z","iopub.status.idle":"2022-09-03T21:07:45.777814Z","shell.execute_reply.started":"2022-09-03T21:07:45.763447Z","shell.execute_reply":"2022-09-03T21:07:45.776050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#run_up_distance\nrace_table['run_up_distance'].describe()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T21:08:34.161639Z","iopub.execute_input":"2022-09-03T21:08:34.162131Z","iopub.status.idle":"2022-09-03T21:08:34.181284Z","shell.execute_reply.started":"2022-09-03T21:08:34.162093Z","shell.execute_reply":"2022-09-03T21:08:34.179398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#purse\nrace_table['purse'].describe()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T21:09:11.592062Z","iopub.execute_input":"2022-09-03T21:09:11.593106Z","iopub.status.idle":"2022-09-03T21:09:11.609294Z","shell.execute_reply.started":"2022-09-03T21:09:11.593048Z","shell.execute_reply":"2022-09-03T21:09:11.607166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## **how many races per (course_type, track_condition, and race_type)?**","metadata":{}},{"cell_type":"code","source":"#races per course_type\nrace_table[['race_number']].groupby(race_table['course_type']).count()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T21:13:09.797739Z","iopub.execute_input":"2022-09-03T21:13:09.798663Z","iopub.status.idle":"2022-09-03T21:13:09.819253Z","shell.execute_reply.started":"2022-09-03T21:13:09.798591Z","shell.execute_reply":"2022-09-03T21:13:09.817466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#races per track_condition\nrace_table[['race_number']].groupby(race_table['track_condition']).count()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T21:14:33.000036Z","iopub.execute_input":"2022-09-03T21:14:33.000864Z","iopub.status.idle":"2022-09-03T21:14:33.018235Z","shell.execute_reply.started":"2022-09-03T21:14:33.000814Z","shell.execute_reply":"2022-09-03T21:14:33.017132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#races per race_type\nrace_table[['race_number']].groupby(race_table['race_type']).count()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T21:15:13.596777Z","iopub.execute_input":"2022-09-03T21:15:13.597687Z","iopub.status.idle":"2022-09-03T21:15:13.615980Z","shell.execute_reply.started":"2022-09-03T21:15:13.597622Z","shell.execute_reply":"2022-09-03T21:15:13.614902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## **How many races played per week / month in 2019 ?**","metadata":{}},{"cell_type":"code","source":"#races per week in 2019\nrace_table.groupby([pd.Grouper(key='race_date', freq='W')])['race_number'].count()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T21:31:32.199511Z","iopub.execute_input":"2022-09-03T21:31:32.200287Z","iopub.status.idle":"2022-09-03T21:31:32.216090Z","shell.execute_reply.started":"2022-09-03T21:31:32.200242Z","shell.execute_reply":"2022-09-03T21:31:32.214980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#races per month\nrace_table.groupby([pd.Grouper(key='race_date', freq='M')])['race_number'].count()","metadata":{"execution":{"iopub.status.busy":"2022-09-03T21:32:10.914868Z","iopub.execute_input":"2022-09-03T21:32:10.915369Z","iopub.status.idle":"2022-09-03T21:32:10.931553Z","shell.execute_reply.started":"2022-09-03T21:32:10.915314Z","shell.execute_reply":"2022-09-03T21:32:10.930473Z"},"trusted":true},"execution_count":null,"outputs":[]}]}