{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to read data from DataFrames with pyActigraphy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Imported packages and input data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The usual suspects:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:46:20.797012Z", "start_time": "2023-01-30T15:46:20.640738Z" } }, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:46:21.029765Z", "start_time": "2023-01-30T15:46:20.798230Z" } }, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:46:22.362016Z", "start_time": "2023-01-30T15:46:21.031406Z" } }, "outputs": [], "source": [ "import pyActigraphy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example, let's generate some input data:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "NB: if you already have your data under a pandas.DataFrame format, jump directly to the next section." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:46:22.365103Z", "start_time": "2023-01-30T15:46:22.363452Z" } }, "outputs": [], "source": [ "N = 1440*7 # 7 days of acquisition at a frequency of 60s." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:46:22.370183Z", "start_time": "2023-01-30T15:46:22.366077Z" } }, "outputs": [], "source": [ "activity = np.random.normal(10,1,N)\n", "light = np.random.normal(100,10,N)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:46:22.373357Z", "start_time": "2023-01-30T15:46:22.371173Z" } }, "outputs": [], "source": [ "non_wear = np.empty(N)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:46:22.376814Z", "start_time": "2023-01-30T15:46:22.374774Z" } }, "outputs": [], "source": [ "# Set up a segment of spurious inactivity\n", "activity[2060:2160] = 0.0\n", "non_wear[2060:2160] = 1.0" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:46:22.382434Z", "start_time": "2023-01-30T15:46:22.380545Z" } }, "outputs": [], "source": [ "d = {'Activity': activity, 'Light': light, 'Non-wear': non_wear}" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:46:22.387956Z", "start_time": "2023-01-30T15:46:22.384391Z" } }, "outputs": [], "source": [ "index = pd.date_range(start='01-01-2020',freq='60s',periods=N)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:46:22.393274Z", "start_time": "2023-01-30T15:46:22.389782Z" } }, "outputs": [], "source": [ "data = pd.DataFrame(index=index,data=d)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:46:22.406545Z", "start_time": "2023-01-30T15:46:22.394383Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " | Activity | \n", "Light | \n", "Non-wear | \n", "
---|---|---|---|
2020-01-01 00:00:00 | \n", "8.550218 | \n", "104.999953 | \n", "0.000000e+00 | \n", "
2020-01-01 00:01:00 | \n", "10.923393 | \n", "95.088518 | \n", "2.194245e-314 | \n", "
2020-01-01 00:02:00 | \n", "8.144349 | \n", "103.872427 | \n", "4.052524e-319 | \n", "
2020-01-01 00:03:00 | \n", "9.285714 | \n", "113.352058 | \n", "NaN | \n", "
2020-01-01 00:04:00 | \n", "10.159414 | \n", "116.400666 | \n", "8.331307e-316 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
2020-01-07 23:55:00 | \n", "9.421655 | \n", "102.225861 | \n", "2.072129e-309 | \n", "
2020-01-07 23:56:00 | \n", "10.571214 | \n", "97.894970 | \n", "7.900019e+305 | \n", "
2020-01-07 23:57:00 | \n", "8.522185 | \n", "126.530327 | \n", "8.157913e-312 | \n", "
2020-01-07 23:58:00 | \n", "10.488261 | \n", "101.407490 | \n", "5.367234e-303 | \n", "
2020-01-07 23:59:00 | \n", "11.041405 | \n", "100.372527 | \n", "1.333605e+241 | \n", "
10080 rows × 3 columns
\n", "