{"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":"#Credit to @KEN MILLER  and MATT OP. I used their code from this notebook for EDA and isolate one race and show speed and time as well as finish position.\n\n\n\n\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport plotly.express as px #graphing\nimport plotly.graph_objects as go #graphing\nfrom plotly.subplots import make_subplots #graphing\nimport plotly.figure_factory as ff #graphing\nimport matplotlib.pyplot as plt #graphing\nimport seaborn as sns #graphing\nimport missingno as msno #describe data\n!pip install pymap3d\nimport pymap3d as pm\n\nfrom shapely.geometry import Point\nfrom shapely.geometry.polygon import Polygon\nimport os\n\ncolors = [\"#FFFFFF\", \"#6CD4FF\", \"#F7DF00\", \"#E60000\"]\n\nfrom plotly.offline import plot, iplot, init_notebook_mode\nimport plotly.graph_objs as go\ninit_notebook_mode(connected=True)\n\nplt.rcParams[\"figure.figsize\"] = (12, 8)\n\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-24T03:18:55.357402Z","iopub.execute_input":"2022-08-24T03:18:55.357908Z","iopub.status.idle":"2022-08-24T03:19:10.162986Z","shell.execute_reply.started":"2022-08-24T03:18:55.357869Z","shell.execute_reply":"2022-08-24T03:19:10.161357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_tracking = pd.read_csv(\"/kaggle/input/big-data-derby-2022/nyra_tracking_table.csv\")\nnyra_start = pd.read_csv(\"/kaggle/input/big-data-derby-2022/nyra_start_table.csv\")\nnyra_race = pd.read_csv(\"/kaggle/input/big-data-derby-2022/nyra_race_table.csv\")\nnyra_2019 = pd.read_csv(\"/kaggle/input/big-data-derby-2022/nyra_2019_complete.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:07:37.503760Z","iopub.execute_input":"2022-08-24T03:07:37.504288Z","iopub.status.idle":"2022-08-24T03:07:51.466200Z","shell.execute_reply.started":"2022-08-24T03:07:37.504244Z","shell.execute_reply":"2022-08-24T03:07:51.464697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_2019.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:07:51.469330Z","iopub.execute_input":"2022-08-24T03:07:51.469922Z","iopub.status.idle":"2022-08-24T03:07:51.496331Z","shell.execute_reply.started":"2022-08-24T03:07:51.469867Z","shell.execute_reply":"2022-08-24T03:07:51.494827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_2019.describe().style.background_gradient(cmap = \"plasma\")","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:07:51.497946Z","iopub.execute_input":"2022-08-24T03:07:51.498435Z","iopub.status.idle":"2022-08-24T03:07:52.958143Z","shell.execute_reply.started":"2022-08-24T03:07:51.498378Z","shell.execute_reply":"2022-08-24T03:07:52.956549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_tracking.track_id.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:07:52.961063Z","iopub.execute_input":"2022-08-24T03:07:52.961597Z","iopub.status.idle":"2022-08-24T03:07:53.290574Z","shell.execute_reply.started":"2022-08-24T03:07:52.961561Z","shell.execute_reply":"2022-08-24T03:07:53.289053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_tracking.race_number.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:07:53.292699Z","iopub.execute_input":"2022-08-24T03:07:53.293369Z","iopub.status.idle":"2022-08-24T03:07:53.351014Z","shell.execute_reply.started":"2022-08-24T03:07:53.293332Z","shell.execute_reply":"2022-08-24T03:07:53.349269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_tracking.program_number.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:07:53.353059Z","iopub.execute_input":"2022-08-24T03:07:53.353562Z","iopub.status.idle":"2022-08-24T03:07:53.685050Z","shell.execute_reply.started":"2022-08-24T03:07:53.353518Z","shell.execute_reply":"2022-08-24T03:07:53.683786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_tracking['race_date'] = pd.to_datetime(nyra_tracking['race_date'])\nnyra_tracking['day'], nyra_tracking['month'] = nyra_tracking['race_date'].dt.day, nyra_tracking['race_date'].dt.month","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:07:53.686927Z","iopub.execute_input":"2022-08-24T03:07:53.687696Z","iopub.status.idle":"2022-08-24T03:07:55.472939Z","shell.execute_reply.started":"2022-08-24T03:07:53.687655Z","shell.execute_reply":"2022-08-24T03:07:55.471634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_tracking0 = nyra_tracking[nyra_tracking[\"track_id\"] == \"AQU\"]\nnyra_tracking1 = nyra_tracking0[nyra_tracking0[\"month\"] == 11]\n\nplt.style.use(\"dark_background\")\nplt.figure(figsize = (16, 8))\nsns.scatterplot(data = nyra_tracking1, x = \"longitude\", y = \"latitude\", hue = \"race_number\", palette = \"Paired\")\n\nplt.title(\"track_id = AQU, Longitude and Latitude by Race Number\")\nplt.legend()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:07:55.474688Z","iopub.execute_input":"2022-08-24T03:07:55.475077Z","iopub.status.idle":"2022-08-24T03:08:11.899878Z","shell.execute_reply.started":"2022-08-24T03:07:55.475040Z","shell.execute_reply":"2022-08-24T03:08:11.898660Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_tracking0 = nyra_tracking[nyra_tracking[\"track_id\"] == \"AQU\"]\nnyra_tracking1 = nyra_tracking0[nyra_tracking0[\"month\"] == 11]\n\nplt.style.use(\"dark_background\")\nplt.figure(figsize = (16, 8))\nsns.scatterplot(data = nyra_tracking1, x = \"longitude\", y = \"latitude\", hue = \"race_number\", palette = \"Paired\")\n\nplt.title(\"track_id = AQU, Longitude and Latitude by Race Number\")\nplt.legend()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:08:11.902126Z","iopub.execute_input":"2022-08-24T03:08:11.902517Z","iopub.status.idle":"2022-08-24T03:08:28.080943Z","shell.execute_reply.started":"2022-08-24T03:08:11.902483Z","shell.execute_reply":"2022-08-24T03:08:28.079436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_tracking0 = nyra_tracking[nyra_tracking[\"track_id\"] == \"SAR\"]\nnyra_tracking1 = nyra_tracking0[nyra_tracking0[\"month\"] == 9]\n\nplt.style.use(\"dark_background\")\nplt.figure(figsize = (16, 8))\nsns.scatterplot(data = nyra_tracking1, x = \"longitude\", y = \"latitude\", hue = \"race_number\", palette = \"Paired\")\n\nplt.title(\"track_id = SAR, Longitude and Latitude by Race Number\")\nplt.legend()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:08:28.085784Z","iopub.execute_input":"2022-08-24T03:08:28.087455Z","iopub.status.idle":"2022-08-24T03:08:30.586290Z","shell.execute_reply.started":"2022-08-24T03:08:28.087398Z","shell.execute_reply":"2022-08-24T03:08:30.585257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_2019.race_number.hist(bins = 12)","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:08:30.588071Z","iopub.execute_input":"2022-08-24T03:08:30.588465Z","iopub.status.idle":"2022-08-24T03:08:30.948015Z","shell.execute_reply.started":"2022-08-24T03:08:30.588431Z","shell.execute_reply":"2022-08-24T03:08:30.947122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"jockey = nyra_2019[nyra_2019[\"jockey\"] == \"Samuel Camacho Jr.\"]\njockey6 = jockey[jockey[\"race_number\"] == 6]\njockeyBEL = jockey6[jockey6[\"track_id\"] == \"BEL\"]\njockeyALW = jockeyBEL[jockeyBEL[\"race_type\"] == \"ALW\"]\njockeyCLM = jockeyBEL[jockeyBEL[\"race_type\"] == \"CLM\"]\njockeyALW = jockeyALW.sort_values(by = \"trakus_index\", ascending = True)\n\nfig = px.scatter(jockeyALW, x = \"longitude\", y = \"latitude\", hover_data = [\"race_type\", \"track_id\"],\n                 animation_frame = \"longitude\",\n                 range_y = (40.7122, 40.718),\n                 range_x = (-73.719, -73.73),\n                 #size = \"trakus_index\",\n                 color = \"trakus_index\", color_continuous_scale = \"Turbo\", range_color = (0, 299),\n                 title = \"Samuel Camacho Jr. - Trakus Index,  Race Number = 6,  track_id = BEL\")\n\nfig.layout.updatemenus[0].buttons[0].args[1]['frame']['duration'] = 30\nfig.layout.updatemenus[0].buttons[0].args[1]['transition']['duration'] = 5\nfig.update_traces(marker = dict(symbol = \"circle-open\", size = 20)) # scaling the markers\nfig.update_layout(template = \"plotly_dark\", font = dict(family = \"PT Sans\", size = 12))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:08:30.949524Z","iopub.execute_input":"2022-08-24T03:08:30.950108Z","iopub.status.idle":"2022-08-24T03:08:32.956346Z","shell.execute_reply.started":"2022-08-24T03:08:30.950072Z","shell.execute_reply":"2022-08-24T03:08:32.954818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"jockey = nyra_2019[nyra_2019[\"jockey\"] == \"Flavien Prat\"]\njockey6 = jockey[jockey[\"race_number\"] == 6]\njockeyBEL = jockey6[jockey6[\"track_id\"] == \"BEL\"]\njockeyALW = jockeyBEL[jockeyBEL[\"race_type\"] == \"ALW\"]\njockeyCLM = jockeyBEL[jockeyBEL[\"race_type\"] == \"CLM\"]\njockeyALW = jockeyALW.sort_values(by = \"trakus_index\", ascending = True)\n\nfig = px.scatter(jockeyALW, x = \"longitude\", y = \"latitude\", hover_data = [\"race_type\", \"track_id\"],\n                 animation_frame = \"longitude\",\n                 range_y = (40.7122, 40.718),\n                 range_x = (-73.719, -73.73),\n                # size = \"trakus_index\",\n                 color = \"trakus_index\", color_continuous_scale = \"Turbo\", range_color = (0, 299),\n                 title = \"Flavien Prat - Trakus Index,  Race Number = 6,  track_id = BEL\")\n\nfig.layout.updatemenus[0].buttons[0].args[1]['frame']['duration'] = 30\nfig.layout.updatemenus[0].buttons[0].args[1]['transition']['duration'] = 5\nfig.update_traces(marker = dict(symbol = \"circle-open\", size = 20)) # scaling the markers\nfig.update_layout(template = \"plotly_dark\", font = dict(family = \"PT Sans\", size = 12))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:08:32.958299Z","iopub.execute_input":"2022-08-24T03:08:32.958752Z","iopub.status.idle":"2022-08-24T03:08:35.004962Z","shell.execute_reply.started":"2022-08-24T03:08:32.958706Z","shell.execute_reply":"2022-08-24T03:08:35.003671Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"jockey = nyra_2019[nyra_2019[\"jockey\"] == \"Flavien Prat\"]\nraces_bel = jockey[jockey[\"track_id\"] == 'BEL']\n\nfor odds in sorted([690, 650, 1840, 70, 520, 2140, 400, 2775, 700, 160, 1910, 1030, 660]):\n    \n    df0 = races_bel[races_bel[\"odds\"] == odds]\n    \n    fig = px.scatter(df0, x = \"longitude\", y = \"latitude\", opacity = 0.8,\n                     hover_data = [\"race_date\", \"distance_id\", \"purse\"],\n                     color = \"trakus_index\", color_continuous_scale = \"Turbo\", #range_color = (0, 399),\n                     title = f\"Flavien Prat Trakus Index Race Pathing,  Odds: {odds}  track_id = BEL\")\n\n    fig.update_traces(marker = dict(symbol = \"square-open\", size = 20)) # scaling the markers\n    fig.update_layout(template = \"plotly_dark\", font = dict(family = \"PT Sans\", size = 12))\n    fig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:10:44.644815Z","iopub.execute_input":"2022-08-24T03:10:44.645328Z","iopub.status.idle":"2022-08-24T03:10:46.472784Z","shell.execute_reply.started":"2022-08-24T03:10:44.645288Z","shell.execute_reply":"2022-08-24T03:10:46.471449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_2019.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:11:16.155035Z","iopub.execute_input":"2022-08-24T03:11:16.156132Z","iopub.status.idle":"2022-08-24T03:11:16.180439Z","shell.execute_reply.started":"2022-08-24T03:11:16.156064Z","shell.execute_reply":"2022-08-24T03:11:16.179154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_start.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:11:34.050951Z","iopub.execute_input":"2022-08-24T03:11:34.052077Z","iopub.status.idle":"2022-08-24T03:11:34.068278Z","shell.execute_reply.started":"2022-08-24T03:11:34.052029Z","shell.execute_reply":"2022-08-24T03:11:34.067125Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_start['race_date'] = pd.to_datetime(nyra_start['race_date'])\nnyra_start['day'], nyra_start['month'] = nyra_start['race_date'].dt.day, nyra_start['race_date'].dt.month","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:11:51.881776Z","iopub.execute_input":"2022-08-24T03:11:51.882497Z","iopub.status.idle":"2022-08-24T03:11:51.904980Z","shell.execute_reply.started":"2022-08-24T03:11:51.882440Z","shell.execute_reply":"2022-08-24T03:11:51.903676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.scatter(nyra_start, x = \"weight_carried\", y = \"odds\", hover_data = [\"race_number\", \"jockey\"],\n                 color = \"odds\", color_continuous_scale = colors, range_color = (0, 9999),\n                 title = \"Odds by Weight Carried\")\n\nfig.update_traces(marker = dict(size = 8, symbol = \"circle\")) # scaling the markers\nfig.update_layout(template = \"plotly_dark\", font = dict(family = \"PT Sans\", size = 20))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:12:04.171836Z","iopub.execute_input":"2022-08-24T03:12:04.172372Z","iopub.status.idle":"2022-08-24T03:12:04.502067Z","shell.execute_reply.started":"2022-08-24T03:12:04.172330Z","shell.execute_reply":"2022-08-24T03:12:04.500989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.scatter(nyra_start, x = \"weight_carried\", y = \"day\", hover_data = [\"race_number\", \"jockey\"],\n                 color = \"odds\", color_continuous_scale = colors, range_color = (0, 9999),\n                 title = \"Odds by Day of Event and Weight Carried\")\n\nfig.update_traces(marker = dict(size = 9, symbol = \"square\")) # scaling the markers\nfig.update_layout(template = \"plotly_dark\", font = dict(family = \"PT Sans\", size = 20))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:12:25.286396Z","iopub.execute_input":"2022-08-24T03:12:25.288198Z","iopub.status.idle":"2022-08-24T03:12:25.804246Z","shell.execute_reply.started":"2022-08-24T03:12:25.288153Z","shell.execute_reply":"2022-08-24T03:12:25.802611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.scatter(nyra_start, x = \"weight_carried\", y = \"month\", hover_data = [\"race_number\", \"jockey\"],\n                 color = \"odds\", color_continuous_scale = colors, range_color = (0, 9999),\n                 title = \"Odds by Month of Event and Weight Carried\")\n\nfig.update_traces(marker = dict(size = 11, symbol = \"circle\")) # scaling the markers\nfig.update_layout(template = \"plotly_dark\", font = dict(family = \"PT Sans\", size = 20))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:12:47.602847Z","iopub.execute_input":"2022-08-24T03:12:47.603567Z","iopub.status.idle":"2022-08-24T03:12:48.106513Z","shell.execute_reply.started":"2022-08-24T03:12:47.603520Z","shell.execute_reply":"2022-08-24T03:12:48.105386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_race.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:13:14.422568Z","iopub.execute_input":"2022-08-24T03:13:14.423121Z","iopub.status.idle":"2022-08-24T03:13:14.443596Z","shell.execute_reply.started":"2022-08-24T03:13:14.423082Z","shell.execute_reply":"2022-08-24T03:13:14.442198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_race.track_condition.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:13:32.273638Z","iopub.execute_input":"2022-08-24T03:13:32.274556Z","iopub.status.idle":"2022-08-24T03:13:32.287769Z","shell.execute_reply.started":"2022-08-24T03:13:32.274509Z","shell.execute_reply":"2022-08-24T03:13:32.286111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.scatter(nyra_race, x = \"post_time\", y = \"run_up_distance\", hover_data = [\"race_number\", \"course_type\"],\n                 color = \"race_number\", color_discrete_sequence = colors, #range_color = (0, 9999),\n                 title = \"Post Time by Run Up Distance\")\n\nfig.update_traces(marker = dict(size = 4, symbol = \"circle\")) # scaling the markers\nfig.update_layout(template = \"plotly_dark\", font = dict(family = \"PT Sans\", size = 20))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:13:49.346391Z","iopub.execute_input":"2022-08-24T03:13:49.346830Z","iopub.status.idle":"2022-08-24T03:13:49.476066Z","shell.execute_reply.started":"2022-08-24T03:13:49.346795Z","shell.execute_reply":"2022-08-24T03:13:49.474673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#You can change the track id, but you will habve to get the coordinates for the finish line polgon at that track\ntrack_id = \"SAR\"\n##### change date to see results of another date - make sure they raced tha day\nrace_date = \"2019-07-24\"\n#change race numebr to see result of another race\nrace_number = 5\ntarget_tracking = nyra_tracking.query(\"track_id == @track_id & race_date == @race_date & race_number == @race_number\").sort_values(\"trakus_index\")\ntarget_tracking","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:20:21.313181Z","iopub.execute_input":"2022-08-24T03:20:21.313686Z","iopub.status.idle":"2022-08-24T03:20:21.559998Z","shell.execute_reply.started":"2022-08-24T03:20:21.313648Z","shell.execute_reply":"2022-08-24T03:20:21.558421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dtime = 0.25 #0.25 second per trakus_index according to the data description.\n#Elevations obtained from google earth\nif track_id == \"AQU\":\n    elevation = 3\nelif track_id == \"BEL\":\n    elevation = 20\nelif track_id == \"SAR\":\n    elevation = 93\n\ntarget_trackings = []\nfor number, group in target_tracking.groupby(\"program_number\"):\n    ecef = np.array(pm.geodetic2ecef(group[\"latitude\"].values, group[\"longitude\"].values, np.array([elevation]*len(group)))).T\n    #Calculate speed [km/h]\n    v_ecef = np.sqrt(np.sum(np.diff(ecef,axis=0) ** 2, axis = 1)) * 3.6 / dtime\n    group[\"time\"] = group[\"trakus_index\"] * dtime -  dtime\n    group[\"speed\"] = np.insert(v_ecef, 0, 0)\n    target_trackings.append(group)\n    print(\"No.\", number,\" Mean speed : {:.2f} km/h\".format(np.mean(v_ecef)))\ntarget_tracking = pd.concat(target_trackings)\ntarget_tracking","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:20:43.954970Z","iopub.execute_input":"2022-08-24T03:20:43.955465Z","iopub.status.idle":"2022-08-24T03:20:44.015771Z","shell.execute_reply.started":"2022-08-24T03:20:43.955429Z","shell.execute_reply":"2022-08-24T03:20:44.014158Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#polygon for saratoga finish line\npoly=[[43.071817, -73.770391],[43.071685, -73.770699],[43.072386, -73.771130],[43.072474,-73.770889]]\n\ndf_poly = pd.DataFrame(poly, columns =['Lat', 'Lon'], dtype = float)\npolygon = Polygon([tuple(x) for x in df_poly[['Lat', 'Lon']].to_numpy()])\n# box at finisds line\n#print (\"Finsh Line Box\",polygon)\n\n# check and see what horses are in the finish box\ntarget_tracking['Within'] = target_tracking.apply(lambda target_tracking: polygon.contains(Point(target_tracking['latitude'], target_tracking['longitude'])), axis=1)\n\n#query only horse in the finish box\nnew_df=target_tracking.query('Within == True')\n\n#drop trakus_index < 30 this will be the first time past the finish line\n\nnew_df = new_df[new_df.trakus_index > 75]\n\n#sort by trakus_index\n\nnew_df.sort_values(by=['trakus_index'], inplace=True)\n\n#drop the duplicate program number \n\nnew_df.drop_duplicates(subset=\"program_number\",keep='first', inplace=True)\n\nprint ('Results')\n\nprint ('Track:',track_id,\"Date:\",race_date,\"Race:\",race_number)\n\nnew_df","metadata":{"execution":{"iopub.status.busy":"2022-08-24T03:21:09.068739Z","iopub.execute_input":"2022-08-24T03:21:09.069202Z","iopub.status.idle":"2022-08-24T03:21:09.225832Z","shell.execute_reply.started":"2022-08-24T03:21:09.069168Z","shell.execute_reply":"2022-08-24T03:21:09.224733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}