{"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\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n# 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\nfiles = []\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        files.append(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-10-20T09:16:02.818229Z","iopub.execute_input":"2022-10-20T09:16:02.818635Z","iopub.status.idle":"2022-10-20T09:16:02.826000Z","shell.execute_reply.started":"2022-10-20T09:16:02.818584Z","shell.execute_reply":"2022-10-20T09:16:02.824927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Reading Files\ndata_df = []\n\nfor file in files:\n    data_df.append(pd.read_csv(file))","metadata":{"execution":{"iopub.status.busy":"2022-10-20T09:17:30.401530Z","iopub.execute_input":"2022-10-20T09:17:30.401994Z","iopub.status.idle":"2022-10-20T09:17:44.466175Z","shell.execute_reply.started":"2022-10-20T09:17:30.401952Z","shell.execute_reply":"2022-10-20T09:17:44.464969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Understanding Data","metadata":{}},{"cell_type":"markdown","source":"## NYRA Tracking Table","metadata":{}},{"cell_type":"code","source":"tracking_df = data_df[0]","metadata":{"execution":{"iopub.status.busy":"2022-10-20T09:17:52.539109Z","iopub.execute_input":"2022-10-20T09:17:52.540280Z","iopub.status.idle":"2022-10-20T09:17:52.545330Z","shell.execute_reply.started":"2022-10-20T09:17:52.540216Z","shell.execute_reply":"2022-10-20T09:17:52.544505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_data = data_df[0][\n    (data_df[0].race_date==\"2019-01-01\")\n    & (data_df[0].track_id==\"AQU\")\n    & (data_df[0].race_number==9)\n    & (data_df[0].program_number=='6  ')].sort_values('trakus_index')","metadata":{"execution":{"iopub.status.busy":"2022-10-19T11:40:21.905281Z","iopub.execute_input":"2022-10-19T11:40:21.905617Z","iopub.status.idle":"2022-10-19T11:40:22.799039Z","shell.execute_reply.started":"2022-10-19T11:40:21.905591Z","shell.execute_reply":"2022-10-19T11:40:22.797819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The above table describes\n\n\n`race_date`:Date of race\n\n\n`track_id`: Location of race\n\n\n`race_number`:Number of race\n\n\n`program_number`:Program nunber\n\n\n`trakus_index`: point of the lat / long of the horse in the race passed as an integer.","metadata":{}},{"cell_type":"code","source":"sample_data","metadata":{"execution":{"iopub.status.busy":"2022-10-15T10:10:49.219266Z","iopub.execute_input":"2022-10-15T10:10:49.219787Z","iopub.status.idle":"2022-10-15T10:10:49.244642Z","shell.execute_reply.started":"2022-10-15T10:10:49.219748Z","shell.execute_reply":"2022-10-15T10:10:49.243187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## NYRA Racing Table","metadata":{}},{"cell_type":"code","source":"# 2\nrace_df = data_df[2]","metadata":{"execution":{"iopub.status.busy":"2022-10-19T11:41:01.860320Z","iopub.execute_input":"2022-10-19T11:41:01.860674Z","iopub.status.idle":"2022-10-19T11:41:01.864985Z","shell.execute_reply.started":"2022-10-19T11:41:01.860646Z","shell.execute_reply":"2022-10-19T11:41:01.864116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## NYRA Start Table","metadata":{}},{"cell_type":"code","source":"data_df[1]=pd.read_csv(files[1],names=['track_id','race_date','race_number','program_number','weight_carried','jockey','odds','position_at_finish'])\nstart_df = data_df[1]","metadata":{"execution":{"iopub.status.busy":"2022-10-19T11:41:04.665759Z","iopub.execute_input":"2022-10-19T11:41:04.666118Z","iopub.status.idle":"2022-10-19T11:41:04.684137Z","shell.execute_reply.started":"2022-10-19T11:41:04.666089Z","shell.execute_reply":"2022-10-19T11:41:04.683454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"start_df","metadata":{"execution":{"iopub.status.busy":"2022-10-19T11:41:07.197924Z","iopub.execute_input":"2022-10-19T11:41:07.198793Z","iopub.status.idle":"2022-10-19T11:41:07.221751Z","shell.execute_reply.started":"2022-10-19T11:41:07.198759Z","shell.execute_reply":"2022-10-19T11:41:07.220945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualization","metadata":{}},{"cell_type":"code","source":"import geopandas as gpd","metadata":{"execution":{"iopub.status.busy":"2022-10-19T11:41:22.478186Z","iopub.execute_input":"2022-10-19T11:41:22.478748Z","iopub.status.idle":"2022-10-19T11:41:22.973787Z","shell.execute_reply.started":"2022-10-19T11:41:22.478719Z","shell.execute_reply":"2022-10-19T11:41:22.972808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import folium\n\n#create a map\nthis_map = folium.Map(prefer_canvas=True)\n\ndef plotDot(point):\n    '''input: series that contains a numeric named latitude and a numeric named longitude\n    this function creates a CircleMarker and adds it to your this_map'''\n    folium.CircleMarker(location=[point.latitude,point.longitude],\n                        radius=2,\n                        weight=5).add_to(this_map)\n\n#use df.apply(,axis=1) to \"iterate\" through every row in your dataframe\nsample_data.apply(plotDot, axis = 1)\n\nthis_map.fit_bounds(this_map.get_bounds())\n\n#Save the map to an HTML file\nthis_map.save('simple_dot_plot.html')\nthis_map","metadata":{"execution":{"iopub.status.busy":"2022-10-19T11:41:38.110574Z","iopub.execute_input":"2022-10-19T11:41:38.111170Z","iopub.status.idle":"2022-10-19T11:41:38.616577Z","shell.execute_reply.started":"2022-10-19T11:41:38.111140Z","shell.execute_reply":"2022-10-19T11:41:38.615719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The total ids of horses available in data are the following","metadata":{}},{"cell_type":"code","source":"all_horses_id = tracking_df['program_number'].unique()\nprint(all_horses_id)","metadata":{"execution":{"iopub.status.busy":"2022-10-19T11:44:08.882650Z","iopub.execute_input":"2022-10-19T11:44:08.883063Z","iopub.status.idle":"2022-10-19T11:44:09.180243Z","shell.execute_reply.started":"2022-10-19T11:44:08.883033Z","shell.execute_reply":"2022-10-19T11:44:09.179054Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(nrows=4,ncols=5,figsize=(20, 8),sharex=True)\nfig.tight_layout(pad=2)\nk = 0\nfor i in range(4):\n    ax[i][0].set_ylabel(\"Count\")\n    for j in range(5):\n        ax[i][j].hist(start_df[start_df.program_number==all_horses_id[k]]['position_at_finish'],edgecolor='black')\n        ax[i][j].set_title(f\"Horse:{all_horses_id[k]}\")\n            \n        if i==3:\n            ax[i][j].set_xlabel(\"Position\")\n            ax[i][j].set_xticks(range(12))\n        k+=1","metadata":{"execution":{"iopub.status.busy":"2022-10-19T11:42:00.024190Z","iopub.execute_input":"2022-10-19T11:42:00.024527Z","iopub.status.idle":"2022-10-19T11:42:02.564633Z","shell.execute_reply.started":"2022-10-19T11:42:00.024499Z","shell.execute_reply":"2022-10-19T11:42:02.563764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}