{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\npd.options.display.max_columns=1000\npd.options.display.max_rows=1000\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport plotly.express as px","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-09-08T06:28:58.973465Z","iopub.execute_input":"2023-09-08T06:28:58.974169Z","iopub.status.idle":"2023-09-08T06:29:02.104820Z","shell.execute_reply.started":"2023-09-08T06:28:58.974116Z","shell.execute_reply":"2023-09-08T06:29:02.103507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_events = pd.read_csv('/kaggle/input/child-mind-institute-detect-sleep-states/train_events.csv')\n# date_table = train_events['timestamp'].str.split('T', expand=True)[0]\n# time_table = train_events['timestamp'].str.split('T', expand=True)[1].str.split('-', expand=True)[0]\n# train_events['timestamp'] = pd.to_datetime(date_table+' '+time_table)\ntrain_events = train_events.dropna()\ntrain_events.head()","metadata":{"execution":{"iopub.status.busy":"2023-09-08T06:29:02.107005Z","iopub.execute_input":"2023-09-08T06:29:02.107943Z","iopub.status.idle":"2023-09-08T06:29:02.191641Z","shell.execute_reply.started":"2023-09-08T06:29:02.107908Z","shell.execute_reply":"2023-09-08T06:29:02.190794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"states = {s:i+1 for i, s in enumerate(train_events['event'].unique())}\nstates","metadata":{"execution":{"iopub.status.busy":"2023-09-08T06:29:02.192864Z","iopub.execute_input":"2023-09-08T06:29:02.193383Z","iopub.status.idle":"2023-09-08T06:29:02.210526Z","shell.execute_reply.started":"2023-09-08T06:29:02.193354Z","shell.execute_reply":"2023-09-08T06:29:02.209320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_events = train_events.replace({'event': states})\ntrain_events","metadata":{"execution":{"iopub.status.busy":"2023-09-08T06:29:02.214039Z","iopub.execute_input":"2023-09-08T06:29:02.214561Z","iopub.status.idle":"2023-09-08T06:29:02.250264Z","shell.execute_reply.started":"2023-09-08T06:29:02.214515Z","shell.execute_reply":"2023-09-08T06:29:02.249167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_parquet('/kaggle/input/child-mind-institute-detect-sleep-states/train_series.parquet')\ntrain.dropna()\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2023-09-08T06:29:02.251966Z","iopub.execute_input":"2023-09-08T06:29:02.252855Z","iopub.status.idle":"2023-09-08T06:30:30.450073Z","shell.execute_reply.started":"2023-09-08T06:29:02.252816Z","shell.execute_reply":"2023-09-08T06:30:30.448861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"chanck_size = 50000\n\nfor index in range(0, len(train), chanck_size):\n    train.loc[index:index+chanck_size, 'hour'] = train.loc[index:index+chanck_size, 'timestamp'].str.split('T', expand=True)[1].str.split('-', expand=True)[0].str.split(':', expand=True)[0]","metadata":{"execution":{"iopub.status.busy":"2023-09-08T06:30:30.451494Z","iopub.execute_input":"2023-09-08T06:30:30.451833Z","iopub.status.idle":"2023-09-08T06:56:09.360093Z","shell.execute_reply.started":"2023-09-08T06:30:30.451804Z","shell.execute_reply":"2023-09-08T06:56:09.359018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.merge(train, train_events, left_on=['series_id','step', 'timestamp'], right_on=['series_id','step', 'timestamp'], how='left')","metadata":{"execution":{"iopub.status.busy":"2023-09-08T06:56:09.361569Z","iopub.execute_input":"2023-09-08T06:56:09.361894Z","iopub.status.idle":"2023-09-08T06:59:17.193168Z","shell.execute_reply.started":"2023-09-08T06:56:09.361866Z","shell.execute_reply":"2023-09-08T06:59:17.191856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del train\ndel train_events","metadata":{"execution":{"iopub.status.busy":"2023-09-08T06:59:17.194582Z","iopub.execute_input":"2023-09-08T06:59:17.194900Z","iopub.status.idle":"2023-09-08T06:59:19.256507Z","shell.execute_reply.started":"2023-09-08T06:59:17.194866Z","shell.execute_reply":"2023-09-08T06:59:19.255202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['event'] = df['event'].fillna(0)","metadata":{"execution":{"iopub.status.busy":"2023-09-08T06:59:19.258152Z","iopub.execute_input":"2023-09-08T06:59:19.258825Z","iopub.status.idle":"2023-09-08T06:59:20.127616Z","shell.execute_reply.started":"2023-09-08T06:59:19.258781Z","shell.execute_reply":"2023-09-08T06:59:20.126023Z"},"trusted":true},"execution_count":null,"outputs":[]}],"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"}}