{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "ecg = pd.read_csv(\"ECG.csv\")\n", "eeg = pd.read_csv(\"EEG.csv\")\n", "labels = pd.read_csv(\"Labels.csv\")" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "scrolled": true }, "outputs": [], "source": [ "Arousal = labels[labels['Label'] == 'Arousal']\n", "Dominance = labels[labels['Label'] == 'Dominance']\n", "Valence = labels[labels['Label'] == 'Valence']" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "labels.shape[0] == Arousal.shape[0] + Dominance.shape[0] + Valence.shape[0]" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "Arousal = Arousal.rename({'Score':'Arousal'}, axis=1)\n", "Dominance = Dominance.rename({'Score':'Dominance'}, axis=1)\n", "Valence = Valence.rename({'Score':'Valence'}, axis=1)" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Index(['ECG1', 'ECG2', 'Person', 'Movie'], dtype='object')\n", "Index(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12',\n", " '13', 'Person', 'Movie'],\n", " dtype='object')\n", "Index(['Score', 'Person', 'Movie', 'Label'], dtype='object')\n" ] } ], "source": [ "print(ecg.columns)\n", "print(eeg.columns)\n", "print(labels.columns)" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(10975232, 16)\n", "(21950464, 4)\n" ] } ], "source": [ "print(eeg.shape)\n", "print(ecg.shape)" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [], "source": [ "ecg = pd.merge(ecg, Arousal.drop('Label', axis=1), how='left', on=['Person', 'Movie'])\n", "ecg = pd.merge(ecg, Dominance.drop('Label', axis=1), how='left', on=['Person', 'Movie'])\n", "ecg = pd.merge(ecg, Valence.drop('Label', axis=1), how='left', on=['Person', 'Movie'])" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "eeg = pd.merge(eeg, Arousal.drop('Label', axis=1), how='left', on=['Person', 'Movie'])\n", "eeg = pd.merge(eeg, Dominance.drop('Label', axis=1), how='left', on=['Person', 'Movie'])\n", "eeg = pd.merge(eeg, Valence.drop('Label', axis=1), how='left', on=['Person', 'Movie'])" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(10975232, 19)\n" ] } ], "source": [ "print(eeg.shape)" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(10975232, 19)\n", "(21950464, 7)\n" ] } ], "source": [ "print(eeg.shape)\n", "print(ecg.shape)" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
012345678910111213PersonMovieArousalDominanceValence
04388.24102.64219.54465.14370.84399.54443.14023.14365.14310.33953.84454.44326.24165.111324
14375.94093.84252.84522.64435.94411.84488.74108.74399.54384.64007.74466.74372.84247.211324
24378.54091.34230.34488.24370.34402.64461.04077.44378.54328.73986.24461.04328.24203.611324
34393.84101.04193.34419.04270.34392.34411.33982.64336.44213.33930.34442.64261.04100.011324
44396.44108.74210.84436.44310.84401.04426.73980.54349.74238.53945.14446.74289.74115.411324
\n", "
" ], "text/plain": [ " 0 1 2 3 4 5 6 7 8 \\\n", "0 4388.2 4102.6 4219.5 4465.1 4370.8 4399.5 4443.1 4023.1 4365.1 \n", "1 4375.9 4093.8 4252.8 4522.6 4435.9 4411.8 4488.7 4108.7 4399.5 \n", "2 4378.5 4091.3 4230.3 4488.2 4370.3 4402.6 4461.0 4077.4 4378.5 \n", "3 4393.8 4101.0 4193.3 4419.0 4270.3 4392.3 4411.3 3982.6 4336.4 \n", "4 4396.4 4108.7 4210.8 4436.4 4310.8 4401.0 4426.7 3980.5 4349.7 \n", "\n", " 9 10 11 12 13 Person Movie Arousal Dominance \\\n", "0 4310.3 3953.8 4454.4 4326.2 4165.1 1 1 3 2 \n", "1 4384.6 4007.7 4466.7 4372.8 4247.2 1 1 3 2 \n", "2 4328.7 3986.2 4461.0 4328.2 4203.6 1 1 3 2 \n", "3 4213.3 3930.3 4442.6 4261.0 4100.0 1 1 3 2 \n", "4 4238.5 3945.1 4446.7 4289.7 4115.4 1 1 3 2 \n", "\n", " Valence \n", "0 4 \n", "1 4 \n", "2 4 \n", "3 4 \n", "4 4 " ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "eeg.head()" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [], "source": [ "ecg.to_csv(\"ECG_Labelled.csv\")\n", "eeg.to_csv(\"EEG_Labelled.csv\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Combine ECG and EEG" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/sf/.local/lib/python3.6/site-packages/numpy/lib/arraysetops.py:472: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison\n", " mask |= (ar1 == a)\n" ] } ], "source": [ "ecg = pd.read_csv(\"ECG_Labelled.csv\", index_col=0)\n", "eeg = pd.read_csv(\"EEG_Labelled.csv\", index_col=0)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
012345678910111213PersonMovieArousalDominanceValence
04388.24102.64219.54465.14370.84399.54443.14023.14365.14310.33953.84454.44326.24165.111324
14375.94093.84252.84522.64435.94411.84488.74108.74399.54384.64007.74466.74372.84247.211324
24378.54091.34230.34488.24370.34402.64461.04077.44378.54328.73986.24461.04328.24203.611324
34393.84101.04193.34419.04270.34392.34411.33982.64336.44213.33930.34442.64261.04100.011324
44396.44108.74210.84436.44310.84401.04426.73980.54349.74238.53945.14446.74289.74115.411324
\n", "
" ], "text/plain": [ " 0 1 2 3 4 5 6 7 8 \\\n", "0 4388.2 4102.6 4219.5 4465.1 4370.8 4399.5 4443.1 4023.1 4365.1 \n", "1 4375.9 4093.8 4252.8 4522.6 4435.9 4411.8 4488.7 4108.7 4399.5 \n", "2 4378.5 4091.3 4230.3 4488.2 4370.3 4402.6 4461.0 4077.4 4378.5 \n", "3 4393.8 4101.0 4193.3 4419.0 4270.3 4392.3 4411.3 3982.6 4336.4 \n", "4 4396.4 4108.7 4210.8 4436.4 4310.8 4401.0 4426.7 3980.5 4349.7 \n", "\n", " 9 10 11 12 13 Person Movie Arousal Dominance \\\n", "0 4310.3 3953.8 4454.4 4326.2 4165.1 1 1 3 2 \n", "1 4384.6 4007.7 4466.7 4372.8 4247.2 1 1 3 2 \n", "2 4328.7 3986.2 4461.0 4328.2 4203.6 1 1 3 2 \n", "3 4213.3 3930.3 4442.6 4261.0 4100.0 1 1 3 2 \n", "4 4238.5 3945.1 4446.7 4289.7 4115.4 1 1 3 2 \n", "\n", " Valence \n", "0 4 \n", "1 4 \n", "2 4 \n", "3 4 \n", "4 4 " ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "eeg.head()" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "ecg_downsampled = ecg[np.arange(len(ecg)) % 2 == 0] # deleting all odd indices" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "44544" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ecg_downsampled[(ecg_downsampled['Person'] == 1) & (ecg_downsampled['Movie'] == 3)].shape[0]" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "ecg_downsampled.reset_index(inplace=True, drop=True)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ECG1ECG2PersonMovieArousalDominanceValence
02046205611324
12039205911324
22041206011324
32039205911324
42040205611324
\n", "
" ], "text/plain": [ " ECG1 ECG2 Person Movie Arousal Dominance Valence\n", "0 2046 2056 1 1 3 2 4\n", "1 2039 2059 1 1 3 2 4\n", "2 2041 2060 1 1 3 2 4\n", "3 2039 2059 1 1 3 2 4\n", "4 2040 2056 1 1 3 2 4" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ecg_downsampled.head()" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "44544" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "eeg[(eeg['Person'] == 1) & (eeg['Movie'] == 3)].shape[0] # check" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "eeg.shape[0] == ecg_downsampled.shape[0] # check" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12',\n", " '13', 'Person', 'Movie', 'Arousal', 'Dominance', 'Valence'],\n", " dtype='object')" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "eeg.columns" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [], "source": [ "del ecg" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "combined = pd.concat([eeg, ecg_downsampled.drop(['Person', 'Movie', 'Arousal', 'Dominance', 'Valence'], axis=1)], axis=1)" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(10975232, 7)" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ecg_downsampled.shape" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(10975232, 21)" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "combined.shape" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12',\n", " '13', 'Person', 'Movie', 'Arousal', 'Dominance', 'Valence', 'ECG1',\n", " 'ECG2'],\n", " dtype='object')" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "combined.columns" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [], "source": [ "combined.to_csv(\"DREAMER_combined.csv\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }