Skip to content

Commit

Permalink
Move group_data and reset_groups from survey
Browse files Browse the repository at this point in the history
  • Loading branch information
rantahar committed Oct 7, 2024
1 parent 8b2dc5f commit c78eb73
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions niimpy/preprocessing/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pandas as pd
import numpy as np
from niimpy.preprocessing import util


# Below, we provide some mappings between standardized survey raw questions and their respective codes
Expand Down Expand Up @@ -116,17 +117,6 @@

group_by_columns = set(["user", "device"])

def group_data(df):
""" Group the dataframe by a standard set of columns listed in
group_by_columns."""
columns = list(group_by_columns & set(df.columns))
return df.groupby(columns)

def reset_groups(df):
""" Reset the grouping, keeping only the original index columns. """
columns = list(group_by_columns & set(df.index.names))
return df.reset_index(columns)


def clean_survey_column_names(df):
"""
Expand Down Expand Up @@ -265,8 +255,8 @@ def calculate_statistic(df):
result[answer_col+"_std"] = df[answer_col].std()
return pd.Series(result)

res = group_data(df).resample(**resample_args).apply(calculate_statistic)
res = reset_groups(res)
res = util.group_data(df).resample(**resample_args).apply(calculate_statistic)
res = util.reset_groups(res)
return res


Expand Down Expand Up @@ -353,5 +343,5 @@ def extract_features_survey(df, features=None):
if 'group' in df:
computed_features['group'] = df.groupby('user')['group'].first()

computed_features = reset_groups(computed_features)
computed_features = util.reset_groups(computed_features)
return computed_features

0 comments on commit c78eb73

Please sign in to comment.