{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":127091,"databundleVersionId":15179667,"sourceType":"competition"}],"dockerImageVersionId":31259,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\n\ndf = pd.read_csv(\"/kaggle/input/cuhkml-2025-classification/dataframe_test.csv\")","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-01-28T09:06:01.965607Z","iopub.execute_input":"2026-01-28T09:06:01.965975Z","iopub.status.idle":"2026-01-28T09:06:02.081196Z","shell.execute_reply.started":"2026-01-28T09:06:01.965945Z","shell.execute_reply":"2026-01-28T09:06:02.080026Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['source_type'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-28T09:06:02.083219Z","iopub.execute_input":"2026-01-28T09:06:02.083562Z","iopub.status.idle":"2026-01-28T09:06:02.092485Z","shell.execute_reply.started":"2026-01-28T09:06:02.083534Z","shell.execute_reply":"2026-01-28T09:06:02.091456Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"bad_mask = df['source_type'] == \"2.10E+18\"\ndf[bad_mask].style.set_properties(\n    subset=['source_type', 'source_tracking_id'], \n    **{'background-color': 'rgb(255, 100, 100)', 'color': 'white'}\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-28T09:06:02.093768Z","iopub.execute_input":"2026-01-28T09:06:02.094148Z","iopub.status.idle":"2026-01-28T09:06:02.120012Z","shell.execute_reply.started":"2026-01-28T09:06:02.094108Z","shell.execute_reply":"2026-01-28T09:06:02.118972Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Swap\ndf.loc[bad_mask, ['source_type', 'source_tracking_id']] = \\\n    df.loc[bad_mask, ['source_tracking_id', 'source_type']].values","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-28T09:06:02.121912Z","iopub.execute_input":"2026-01-28T09:06:02.122190Z","iopub.status.idle":"2026-01-28T09:06:02.143385Z","shell.execute_reply.started":"2026-01-28T09:06:02.122165Z","shell.execute_reply":"2026-01-28T09:06:02.142009Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"next_action = df.groupby(['courier_id', 'wave_index'])['source_type'].shift(-1)\n\n# Next=PICKUP -> Curr=PICKUP\n# Next=DELIVERY -> Curr=DELIVERY\n# Next=NaN (End of Delivery) -> Curr=DELIVERY. This logic is validated on training set.\ndf['action_type'] = next_action.map({'PICKUP': 0, 'DELIVERY': 1}).fillna(1).astype(int)\n\npd.DataFrame({\n    'order': range(len(df)),\n    'action_type_DELIVERY': df['action_type']\n}).to_csv(\"submission.csv\", index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-28T09:06:02.144916Z","iopub.execute_input":"2026-01-28T09:06:02.145347Z","iopub.status.idle":"2026-01-28T09:06:02.189924Z","shell.execute_reply.started":"2026-01-28T09:06:02.145317Z","shell.execute_reply":"2026-01-28T09:06:02.188920Z"}},"outputs":[],"execution_count":null}]}