Convert event time to datetime.
parent
763b970a42
commit
19cddaa634
|
@ -39,13 +39,22 @@ def extract_stressful_events(df_esm: pd.DataFrame) -> pd.DataFrame:
|
|||
# 2.
|
||||
df_esm_event_stress = detect_stressful_event(df_esm_sam_clean)
|
||||
|
||||
# Join all the features related to the events.
|
||||
# Join to the previously calculated features related to the events.
|
||||
df_esm_events = df_esm_event_threat_challenge_mean_wide.join(
|
||||
df_esm_event_stress[
|
||||
GROUP_QUESTIONNAIRES_BY + ["event_present", "event_stressfulness"]
|
||||
].set_index(GROUP_QUESTIONNAIRES_BY)
|
||||
)
|
||||
|
||||
# 3.
|
||||
df_esm_event_time = convert_event_time(df_esm_sam_clean)
|
||||
|
||||
df_esm_events = df_esm_events.join(
|
||||
df_esm_event_time[GROUP_QUESTIONNAIRES_BY.append("event_time")].set_index(
|
||||
GROUP_QUESTIONNAIRES_BY
|
||||
)
|
||||
)
|
||||
|
||||
return df_esm_events
|
||||
|
||||
|
||||
|
@ -98,3 +107,14 @@ def detect_stressful_event(df_esm_sam_clean: pd.DataFrame) -> pd.DataFrame:
|
|||
event_stressfulness=lambda x: x.esm_user_answer_numeric,
|
||||
)
|
||||
return df_esm_event_stress
|
||||
|
||||
|
||||
def convert_event_time(df_esm_sam_clean: pd.DataFrame) -> pd.DataFrame:
|
||||
df_esm_event_time = df_esm_sam_clean[
|
||||
df_esm_sam_clean["questionnaire_id"] == QUESTIONNAIRE_ID_SAM.get("event_time")
|
||||
].assign(
|
||||
event_time=lambda x: pd.to_datetime(
|
||||
x.esm_user_answer, errors="coerce", infer_datetime_format=True, exact=True
|
||||
)
|
||||
)
|
||||
return df_esm_event_time
|
||||
|
|
Loading…
Reference in New Issue