{"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\nimport numpy as np","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-09-13T13:29:02.859261Z","iopub.execute_input":"2023-09-13T13:29:02.859753Z","iopub.status.idle":"2023-09-13T13:29:02.865462Z","shell.execute_reply.started":"2023-09-13T13:29:02.859712Z","shell.execute_reply":"2023-09-13T13:29:02.864158Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Read in the ground truth file","metadata":{}},{"cell_type":"code","source":"ground_truth = pd.read_csv(\"/kaggle/input/child-mind-institute-detect-sleep-states/train_events.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-09-13T13:29:02.868246Z","iopub.execute_input":"2023-09-13T13:29:02.869073Z","iopub.status.idle":"2023-09-13T13:29:02.903356Z","shell.execute_reply.started":"2023-09-13T13:29:02.869033Z","shell.execute_reply":"2023-09-13T13:29:02.902534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Convert timestamp using UTC","metadata":{}},{"cell_type":"code","source":"df = ground_truth.copy()\ndf[\"timestamp\"] = pd.to_datetime(df[\"timestamp\"],utc=True)\ndf[\"hour\"] = df[\"timestamp\"].dt.hour\n# filter for mornings and afternons\ndf_morning   = df.loc[df[\"hour\"] <= 12].copy()\ndf_afternoon = df.loc[df[\"hour\"]  > 12].copy()\n\nprint(\"Wake in the morning:        \",df_morning.loc[df_morning[\"event\"] == \"wakeup\"].shape[0])\nprint(\"Go to sleep in the morning: \",df_morning.loc[df_morning[\"event\"] == \"onset\"].shape[0])\nprint(\"Sleep in the afternoon:     \",df_afternoon.loc[df_afternoon[\"event\"] == \"onset\"].shape[0])\nprint(\"Wake in the afternoon:      \",df_afternoon.loc[df_afternoon[\"event\"] == \"wakeup\"].shape[0])","metadata":{"execution":{"iopub.status.busy":"2023-09-13T13:29:02.905026Z","iopub.execute_input":"2023-09-13T13:29:02.905687Z","iopub.status.idle":"2023-09-13T13:29:02.983962Z","shell.execute_reply.started":"2023-09-13T13:29:02.905647Z","shell.execute_reply":"2023-09-13T13:29:02.982736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Use local time","metadata":{}},{"cell_type":"code","source":"df = ground_truth.copy()\ndf['timestamp'] = pd.to_datetime(df['timestamp']).apply(lambda t: t.tz_localize(None))\ndf[\"hour\"] = df[\"timestamp\"].dt.hour\n# filter for mornings and afternons\ndf_morning   = df.loc[df[\"hour\"] <= 12].copy()\ndf_afternoon = df.loc[df[\"hour\"]  > 12].copy()\n\nprint(\"Wake in the morning:        \",df_morning.loc[df_morning[\"event\"] == \"wakeup\"].shape[0])\nprint(\"Go to sleep in the morning: \",df_morning.loc[df_morning[\"event\"] == \"onset\"].shape[0])\nprint(\"Sleep in the afternoon:     \",df_afternoon.loc[df_afternoon[\"event\"] == \"onset\"].shape[0])\nprint(\"Wake in the afternoon:      \",df_afternoon.loc[df_afternoon[\"event\"] == \"wakeup\"].shape[0])","metadata":{"execution":{"iopub.status.busy":"2023-09-13T13:29:02.985333Z","iopub.execute_input":"2023-09-13T13:29:02.985747Z","iopub.status.idle":"2023-09-13T13:29:03.144550Z","shell.execute_reply.started":"2023-09-13T13:29:02.985707Z","shell.execute_reply":"2023-09-13T13:29:03.143229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Conclusion: local time makes more sense!","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"}}