{"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-10-06T12:25:23.821908Z","iopub.execute_input":"2022-10-06T12:25:23.822373Z","iopub.status.idle":"2022-10-06T12:25:23.852831Z","shell.execute_reply.started":"2022-10-06T12:25:23.822280Z","shell.execute_reply":"2022-10-06T12:25:23.851232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport os\n","metadata":{"execution":{"iopub.status.busy":"2022-10-06T12:25:23.855414Z","iopub.execute_input":"2022-10-06T12:25:23.855963Z","iopub.status.idle":"2022-10-06T12:25:23.863413Z","shell.execute_reply.started":"2022-10-06T12:25:23.855915Z","shell.execute_reply":"2022-10-06T12:25:23.861831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(\"../input/big-data-derby-2022/nyra_2019_complete.csv\")\ndf1 = pd.read_csv(\"../input/big-data-derby-2022/nyra_race_table.csv\")\ndf2 = pd.read_csv(\"../input/big-data-derby-2022/nyra_start_table.csv\")\ndff = pd.read_csv(\"../input/big-data-derby-2022/nyra_tracking_table.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-10-06T12:25:23.865638Z","iopub.execute_input":"2022-10-06T12:25:23.866221Z","iopub.status.idle":"2022-10-06T12:25:54.009200Z","shell.execute_reply.started":"2022-10-06T12:25:23.866167Z","shell.execute_reply":"2022-10-06T12:25:54.000310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dff.head()","metadata":{"execution":{"iopub.status.busy":"2022-10-06T12:25:54.012226Z","iopub.execute_input":"2022-10-06T12:25:54.012702Z","iopub.status.idle":"2022-10-06T12:25:54.044861Z","shell.execute_reply.started":"2022-10-06T12:25:54.012666Z","shell.execute_reply":"2022-10-06T12:25:54.043926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dff['track_id'].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-10-06T12:25:54.046223Z","iopub.execute_input":"2022-10-06T12:25:54.049256Z","iopub.status.idle":"2022-10-06T12:25:54.399695Z","shell.execute_reply.started":"2022-10-06T12:25:54.049198Z","shell.execute_reply":"2022-10-06T12:25:54.398251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dff['track_id'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-10-06T12:25:54.401463Z","iopub.execute_input":"2022-10-06T12:25:54.401859Z","iopub.status.idle":"2022-10-06T12:25:54.743715Z","shell.execute_reply.started":"2022-10-06T12:25:54.401826Z","shell.execute_reply":"2022-10-06T12:25:54.742283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head(30)\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_aqu_nyear = dff[(dff['track_id'] == 'AQU') & (dff['race_date'] == '2019-01-01')]","metadata":{"execution":{"iopub.status.busy":"2022-10-06T12:25:54.781049Z","iopub.execute_input":"2022-10-06T12:25:54.781449Z","iopub.status.idle":"2022-10-06T12:25:55.504278Z","shell.execute_reply.started":"2022-10-06T12:25:54.781402Z","shell.execute_reply":"2022-10-06T12:25:55.503438Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_aqu_nyear.head()\ndf_aqu_nyear.shape","metadata":{"execution":{"iopub.status.busy":"2022-10-06T12:25:55.506371Z","iopub.execute_input":"2022-10-06T12:25:55.506841Z","iopub.status.idle":"2022-10-06T12:25:55.516104Z","shell.execute_reply.started":"2022-10-06T12:25:55.506781Z","shell.execute_reply":"2022-10-06T12:25:55.514391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dff.shape","metadata":{"execution":{"iopub.status.busy":"2022-10-06T12:25:55.519362Z","iopub.execute_input":"2022-10-06T12:25:55.519806Z","iopub.status.idle":"2022-10-06T12:25:55.531952Z","shell.execute_reply.started":"2022-10-06T12:25:55.519770Z","shell.execute_reply":"2022-10-06T12:25:55.530655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_aqu_nyear['program_number'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-10-06T12:25:55.533611Z","iopub.execute_input":"2022-10-06T12:25:55.534110Z","iopub.status.idle":"2022-10-06T12:25:55.550451Z","shell.execute_reply.started":"2022-10-06T12:25:55.534074Z","shell.execute_reply":"2022-10-06T12:25:55.549574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-10-06T12:25:55.551766Z","iopub.execute_input":"2022-10-06T12:25:55.552911Z","iopub.status.idle":"2022-10-06T12:25:55.581395Z","shell.execute_reply.started":"2022-10-06T12:25:55.552870Z","shell.execute_reply":"2022-10-06T12:25:55.580251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-10-06T12:26:34.428095Z","iopub.execute_input":"2022-10-06T12:26:34.428589Z","iopub.status.idle":"2022-10-06T12:26:36.101773Z","shell.execute_reply.started":"2022-10-06T12:26:34.428551Z","shell.execute_reply":"2022-10-06T12:26:36.100430Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.rename(columns = {'2019-01-01':'date'}, inplace = True)\n","metadata":{"execution":{"iopub.status.busy":"2022-10-06T12:36:09.475067Z","iopub.execute_input":"2022-10-06T12:36:09.475480Z","iopub.status.idle":"2022-10-06T12:36:09.483789Z","shell.execute_reply.started":"2022-10-06T12:36:09.475447Z","shell.execute_reply":"2022-10-06T12:36:09.482614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import statsmodels.api as sm\nimport seaborn as sns\n\nimport pyarrow.parquet as pq\nimport pyarrow as pa","metadata":{"execution":{"iopub.status.busy":"2022-10-06T12:36:12.947579Z","iopub.execute_input":"2022-10-06T12:36:12.948017Z","iopub.status.idle":"2022-10-06T12:36:12.953750Z","shell.execute_reply.started":"2022-10-06T12:36:12.947982Z","shell.execute_reply":"2022-10-06T12:36:12.952903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2.head()","metadata":{"execution":{"iopub.status.busy":"2022-10-06T12:37:18.178328Z","iopub.execute_input":"2022-10-06T12:37:18.178775Z","iopub.status.idle":"2022-10-06T12:37:18.195160Z","shell.execute_reply.started":"2022-10-06T12:37:18.178744Z","shell.execute_reply":"2022-10-06T12:37:18.193760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2.columns=['track_id', 'race_date', 'race_number', 'program_number', 'weight_carried', 'jockey', 'odds', 'position_at_finish']","metadata":{"execution":{"iopub.status.busy":"2022-10-06T12:38:21.855656Z","iopub.execute_input":"2022-10-06T12:38:21.856203Z","iopub.status.idle":"2022-10-06T12:38:21.863516Z","shell.execute_reply.started":"2022-10-06T12:38:21.856164Z","shell.execute_reply":"2022-10-06T12:38:21.862059Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2.head()","metadata":{"execution":{"iopub.status.busy":"2022-10-06T12:38:37.741281Z","iopub.execute_input":"2022-10-06T12:38:37.741715Z","iopub.status.idle":"2022-10-06T12:38:37.758442Z","shell.execute_reply.started":"2022-10-06T12:38:37.741672Z","shell.execute_reply":"2022-10-06T12:38:37.757181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(df1.shape, df2.shape)","metadata":{"execution":{"iopub.status.busy":"2022-10-06T13:03:38.765853Z","iopub.execute_input":"2022-10-06T13:03:38.766994Z","iopub.status.idle":"2022-10-06T13:03:38.772914Z","shell.execute_reply.started":"2022-10-06T13:03:38.766953Z","shell.execute_reply":"2022-10-06T13:03:38.771476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"start_t = df2.merge(df1, on=['track_id','race_date', 'race_number'], how='inner')\n","metadata":{"execution":{"iopub.status.busy":"2022-10-06T13:05:50.143857Z","iopub.execute_input":"2022-10-06T13:05:50.144403Z","iopub.status.idle":"2022-10-06T13:05:50.197107Z","shell.execute_reply.started":"2022-10-06T13:05:50.144364Z","shell.execute_reply":"2022-10-06T13:05:50.195700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(start_t.shape)\nstart_t.head()","metadata":{"execution":{"iopub.status.busy":"2022-10-06T13:06:26.390026Z","iopub.execute_input":"2022-10-06T13:06:26.390608Z","iopub.status.idle":"2022-10-06T13:06:26.414113Z","shell.execute_reply.started":"2022-10-06T13:06:26.390567Z","shell.execute_reply":"2022-10-06T13:06:26.412835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.express as px","metadata":{"execution":{"iopub.status.busy":"2022-10-06T13:18:42.235484Z","iopub.execute_input":"2022-10-06T13:18:42.236189Z","iopub.status.idle":"2022-10-06T13:18:43.428685Z","shell.execute_reply.started":"2022-10-06T13:18:42.236134Z","shell.execute_reply":"2022-10-06T13:18:43.427291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tid_weight = px.bar(start_t, x='weight_carried', y='track_id')","metadata":{"execution":{"iopub.status.busy":"2022-10-06T13:21:22.917339Z","iopub.execute_input":"2022-10-06T13:21:22.917924Z","iopub.status.idle":"2022-10-06T13:21:24.482453Z","shell.execute_reply.started":"2022-10-06T13:21:22.917878Z","shell.execute_reply":"2022-10-06T13:21:24.481268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tid_weight.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-06T13:21:47.825988Z","iopub.execute_input":"2022-10-06T13:21:47.829284Z","iopub.status.idle":"2022-10-06T13:21:47.938662Z","shell.execute_reply.started":"2022-10-06T13:21:47.829208Z","shell.execute_reply":"2022-10-06T13:21:47.937448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df1.groupby(['race_date'])['race_number'].count() #number of races, grouped by race date ","metadata":{"execution":{"iopub.status.busy":"2022-10-06T13:32:09.131537Z","iopub.execute_input":"2022-10-06T13:32:09.131955Z","iopub.status.idle":"2022-10-06T13:32:09.149208Z","shell.execute_reply.started":"2022-10-06T13:32:09.131922Z","shell.execute_reply":"2022-10-06T13:32:09.148089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"track_count = df1['track_id'].value_counts().index\ntrack_count","metadata":{"execution":{"iopub.status.busy":"2022-10-06T13:35:16.437385Z","iopub.execute_input":"2022-10-06T13:35:16.437775Z","iopub.status.idle":"2022-10-06T13:35:16.451305Z","shell.execute_reply.started":"2022-10-06T13:35:16.437745Z","shell.execute_reply":"2022-10-06T13:35:16.449744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.bar(x = df1['track_id'].value_counts().index, height = df1['track_id'].value_counts())","metadata":{"execution":{"iopub.status.busy":"2022-10-06T13:36:15.274511Z","iopub.execute_input":"2022-10-06T13:36:15.275063Z","iopub.status.idle":"2022-10-06T13:36:15.539033Z","shell.execute_reply.started":"2022-10-06T13:36:15.275022Z","shell.execute_reply":"2022-10-06T13:36:15.537743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2[df2['position_at_finish'] == 1] # finding winners for every race ","metadata":{"execution":{"iopub.status.busy":"2022-10-06T13:37:35.529933Z","iopub.execute_input":"2022-10-06T13:37:35.530373Z","iopub.status.idle":"2022-10-06T13:37:35.553597Z","shell.execute_reply.started":"2022-10-06T13:37:35.530340Z","shell.execute_reply":"2022-10-06T13:37:35.552784Z"},"trusted":true},"execution_count":null,"outputs":[]}]}