Dwayne Dillen
Dwayne Dillen

Reputation: 1

Why does my python for loop only takes the last value of the loop

I'm currently working on a script in python In this part of the script i want to make a loop to get the mean peak value in each window.

df_window['Phasic_mean'] = 0
for a in range(1,len(df_window)-1):
    Phasic_mean = np.mean(df_window['Data'][a][0]/df_window_EDA['Data'][a][0])

With the loop above, I only get the last value (from the last window). Can someone help me to make the loop so that I get the value of each window in a dataframe.

Thank you in advance

Upvotes: 0

Views: 463

Answers (1)

balderman
balderman

Reputation: 23825

make sure you collect the calculation result into a data structure. see means below

menas = []
df_window['Phasic_mean'] = 0
for a in range(1,len(df_window)-1):
    means.append(np.mean(df_window['Data'][a][0]/df_window_EDA['Data'][a][0])) 

Upvotes: 1

Related Questions