CSV Column Average Code

OS (e.g. Win10):
PsychoPy version (e.g.2.5):
Standard Standalone? (y)
What are you trying to achieve?:

Hello Everyone,

I hope you are having an amazing day! I am in the final stages of creating an experiment, so I am trying to clean up my CSV output to make analysis more efficient.

I am trying to add code to my experiment to take the average of a participant’s performance in a loop and make a new column with the participant’s average score.

Here is what I have so far:

Begin Experiment-

total_correct = 0
num_trials = 0

Begin Routine-

for trial in range(12): 

    if response == 'corrKey':  
        total_correct += 1

    num_trials += 1

End Experiment-

average_correct = total_correct / num_trials

thisExp.addData('PTAvg', average_correct)

I have had no luck with this and decided it might be most prudent to reach out for assistance. Thanks

for trial in range(12) will give trial the numerical values 0 to 11. If response is a list of responses then you need to add [trial] to it to identify each one.

1 Like