'sum dataframe column and store as new variable for multiple different data frames

I am analysing eye tracking data. For each trial I have a new eye tracking Dataframe "gaze data". I want to sum the values of the column '3_1' for each Dataframe separately.

This value should be stored in my "trials" Dataframe which has one row per trial.

# select eyetracking data for the trial:
for index, trial in trials.iterrows():      
    gazedata = select_eyedata(trial,index,etData)

 trials['lookRight'] = gazedata['lookRight'].sum()
 trials['lookLeft'] = gazedata['lookLeft'].sum()
 trials['lookUp'] = gazedata['lookUp'].sum()
 trials['lookDown'] = gazedata['lookDown'].sum()

The problem with the code above is that I get the same value for each trial in my trials Dataframe. Instead for each index in trials I need a new value which is the sum of the corresponding gaze data column.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source