{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":59156,"databundleVersionId":13874099,"sourceType":"competition"}],"dockerImageVersionId":31153,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\n\n\ndef load_all_annotations(base_folder):\n\n    all_data = pd.DataFrame()\n\n    for lab_id in os.listdir(base_folder):\n        lab_folder = os.path.join(base_folder, lab_id)\n\n   \n        if os.path.isdir(lab_folder):\n\n            for file in os.listdir(lab_folder):\n                if file.endswith('.parquet'):\n                    file_path = os.path.join(lab_folder, file)\n                    temp_data = pd.read_parquet(file_path)\n                    video_id = os.path.splitext(file)[0]  # 去掉文件扩展名\n                    temp_data['video_id'] = video_id\n                    temp_data['lab_id'] = lab_id  # 添加实验室 ID\n\n                    # 合并到总 DataFrame\n                    all_data = pd.concat([all_data, temp_data], ignore_index=True)\n\n    return all_data\n\nannotation_folder = '/kaggle/input/MABe-mouse-behavior-detection/train_annotation/'\n\nannotation_data = load_all_annotations(annotation_folder)\nannotation_data","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-10-13T05:24:50.801348Z","iopub.execute_input":"2025-10-13T05:24:50.801629Z","iopub.status.idle":"2025-10-13T05:25:01.693816Z","shell.execute_reply.started":"2025-10-13T05:24:50.801594Z","shell.execute_reply":"2025-10-13T05:25:01.692813Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"single = annotation_data[annotation_data['agent_id'] == annotation_data['target_id']]  # agent_id 等於 target_id 的行\npair = annotation_data[annotation_data['agent_id'] != annotation_data['target_id']]  # agent_id 不等於 target_id 的行\n\n# 儲存兩個 DataFrame\nsingle.to_csv('single.csv', index=False)  # 儲存為 CSV\npair.to_csv('pair.csv', index=False)  # 儲存為 CSV\n\n#print(\"Data has been split and saved successfully.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-13T05:25:21.395467Z","iopub.execute_input":"2025-10-13T05:25:21.396069Z","iopub.status.idle":"2025-10-13T05:25:21.659024Z","shell.execute_reply.started":"2025-10-13T05:25:21.396029Z","shell.execute_reply":"2025-10-13T05:25:21.657807Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"single","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-13T05:25:31.716303Z","iopub.execute_input":"2025-10-13T05:25:31.716658Z","iopub.status.idle":"2025-10-13T05:25:31.728721Z","shell.execute_reply.started":"2025-10-13T05:25:31.716629Z","shell.execute_reply":"2025-10-13T05:25:31.727667Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nprint(os.getcwd())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-13T05:25:43.927445Z","iopub.execute_input":"2025-10-13T05:25:43.927829Z","iopub.status.idle":"2025-10-13T05:25:43.933321Z","shell.execute_reply.started":"2025-10-13T05:25:43.927802Z","shell.execute_reply":"2025-10-13T05:25:43.932411Z"}},"outputs":[],"execution_count":null}]}