Created
April 26, 2021 07:57
-
-
Save pietrocolombo/d521b7b173f4edd686c047837f0e7c0d to your computer and use it in GitHub Desktop.
Mean and std on 8 subsequent rows on roll, pitch e module parameters of every accelerometer. Dataframe has been splitted by class and by user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_mean_variance(dataframe): | |
new_row = {} | |
for field in ['user', 'gender', 'age', 'how_tall_in_meters', 'weight', 'body_mass_index', 'class']: | |
new_row[field] = dataframe[field].iloc[0] | |
for field in ['roll1', 'pitch1', 'roll2', 'pitch2', 'roll3', 'pitch3','roll4', 'pitch4']: | |
new_row[field] = np.var(dataframe[field]) | |
for i in range (1, 5): | |
x_list = dataframe[f'x{i}'] | |
y_list = dataframe[f'y{i}'] | |
z_list = dataframe[f'z{i}'] | |
x = x_list.sum() | |
y = y_list.sum() | |
z = z_list.sum() | |
new_row[str(f'accel{i}')] = np.sqrt(np.power(x, 2) + np.power(y, 2) + np.power(z, 2))/x_list.shape[0] | |
return new_row | |
avg_df = pd.DataFrame() | |
for class_action in df['class'].unique(): | |
class_df = df.loc[df['class'] == class_action] | |
for user in class_df['user'].unique(): | |
class_user_df = class_df.loc[class_df['user'] == user] | |
n_instance = class_user_df.shape[0] | |
for i in range(int(np.ceil(n_instance/7))): | |
avg_df = avg_df.append(make_mean_variance(class_user_df[i*7:min((i+1)*7+1, n_instance)]), ignore_index=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment