{"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":"import numpy as np\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2022-07-09T19:05:01.526188Z","iopub.execute_input":"2022-07-09T19:05:01.526813Z","iopub.status.idle":"2022-07-09T19:05:01.551389Z","shell.execute_reply.started":"2022-07-09T19:05:01.526711Z","shell.execute_reply":"2022-07-09T19:05:01.550740Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# read data\n# train = pd.read_csv('/kaggle/input/foursquare-location-matching/train.csv')\ntrain = pd.read_csv('../input/the-real-train-for-foursquare/train.csv')\ntest = pd.read_csv('/kaggle/input/foursquare-location-matching/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-09T19:05:01.552830Z","iopub.execute_input":"2022-07-09T19:05:01.553314Z","iopub.status.idle":"2022-07-09T19:05:11.074304Z","shell.execute_reply.started":"2022-07-09T19:05:01.553280Z","shell.execute_reply":"2022-07-09T19:05:11.073348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# use name/address/longitude/latitude as key to match \"point of interest\" column to test.csv\nexact_match = train.groupby(['name','longitude','latitude'],as_index=False)['point_of_interest'].first()\ntest = test.merge(exact_match,how='left')\ntest.loc[:,['id','point_of_interest']]","metadata":{"execution":{"iopub.status.busy":"2022-07-09T19:15:22.348576Z","iopub.execute_input":"2022-07-09T19:15:22.348937Z","iopub.status.idle":"2022-07-09T19:15:29.429543Z","shell.execute_reply.started":"2022-07-09T19:15:22.348876Z","shell.execute_reply":"2022-07-09T19:15:29.428783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# if found exact match in train.csv,submit trivial matches (self only). if not found, submit nothing.\ntest['matches'] = test.apply(lambda x: '' if pd.isnull(x['point_of_interest']) else x['id'],axis=1)\ntest.loc[:,['id','matches']]","metadata":{"execution":{"iopub.status.busy":"2022-07-09T19:23:42.490686Z","iopub.execute_input":"2022-07-09T19:23:42.491005Z","iopub.status.idle":"2022-07-09T19:23:42.504490Z","shell.execute_reply.started":"2022-07-09T19:23:42.490970Z","shell.execute_reply":"2022-07-09T19:23:42.503483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ssub = pd.read_csv(\"../input/foursquare-location-matching/sample_submission.csv\")\nssub = ssub.drop(columns=\"matches\")\nssub = ssub.merge(test.loc[:,[\"id\",\"matches\"]])\nssub.to_csv(\"submission.csv\", index=False)\n\nssub.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T19:23:46.717070Z","iopub.execute_input":"2022-07-09T19:23:46.718153Z","iopub.status.idle":"2022-07-09T19:23:46.747587Z","shell.execute_reply.started":"2022-07-09T19:23:46.718097Z","shell.execute_reply":"2022-07-09T19:23:46.746886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}