<jupyter_start><jupyter_text>Merge mood,location, and the primary dataset (sensor data and self-reporetd context) based on the timestamp.<jupyter_code>%matplotlib inline
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
import gzip
import pandas as pd
import os
from io import StringIO
import glob
import datetime

plt.rcParams['figure.figsize'] = (15, 10)

path1 =r'C:\Users\dihla\Desktop\ExtraSensory_data\ExtraSensory.per_uuid_mood_labels\Mood_csv' # use your path
path2 =r'C:\Users\dihla\Desktop\ExtraSensory_data\ExtraSensory.per_uuid_features_labels\primary_csv' # use your path
path3 =r'C:\Users\dihla\Desktop\ExtraSensory_data\ExtraSensory.per_uuid_absolute_location\location_csv' # use your path

#Read mood file
moodFiles = glob.glob(path1 + "/*.csv")
#Read primary data
primFiles = glob.glob(path2 + "/*.csv")
#Read location
locFiles = glob.glob(path3 + "/*.csv")

dfs_mood = [pd.read_csv(fp) for fp in moodFiles]
dfs_prim = [pd.read_csv(fp) for fp in primFiles]
dfs_loc = [pd.read_csv(fp) for fp in locFiles]


#df = pd.concat(dfs_mood)
person=1
pList=[]
list_ = []

for mood_f, prim_f, loc_f in  zip(dfs_mood, dfs_prim, dfs_loc):
    
    mood_data=mood_f.dropna()
    count_row = mood_data.shape[0]
    mood_data['person'] = np.nan
    
    #Select persons having at least 100 samples
    if mood_data.shape[0]>999:   
        pList.append(person) 
        mood_data.loc[:,'person']=pd.Series(np.repeat(person, count_row), index=mood_data.index)
        #Merge data using inner join of timestamps
        merged_data=pd.merge(mood_data, prim_f, on='timestamp', how='inner')
        merged_data=pd.merge(merged_data, loc_f, on='timestamp', how='inner')
        
        list_.append(merged_data)
        
    else:
        print('Person ', person)
    person=person+1

merged_frame = pd.concat(list_, axis = 0, ignore_index = True, sort=False)
#merged_frame.to_csv(r'C:\Users\dihla\Desktop\ExtraSensory_data\Merged_Mood_Primary_data\Mood_primary.csv')
#Save the merged file
merged_frame.to_csv('data/Mood_primary_loc_18.csv') # Use youe own path
merged_frame.shape
merged_frame.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11515430677107324, 'fraction_numerical': 0.010594196222938737, 'mean_word_length': 4.68586387434555, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '236918', 'license': 'MIT', 'n_tokens_mistral': 816, 'n_tokens_neox': 788, 'n_words': 169, 'path': 'D1.merge_mood_context_location_data_gen.ipynb', 'repo_name': 'data-intelligence-for-health-lab/mHealth_Emotional_State-Transition_Detection_Public', 'size': '2171'}