0

so I have a dataframe with emotions as column headers and float scores of length 320 as the row values and I'm trying to create a loop that averages the score for every 10 scores in the series across all 4 emotions so I should have 40 averages the first 10 are for happy, next 10 for sad etc... Ideally stored as a dictionary or new dataframe with emotions as columns and average scores as rows or values.

With the loop below I get some results but nesting the loops correctly is the problem. Im sure someone can point me in the right direction. Thanks.

rolling_avgs = {}
emotions = ['happy', 'sad', 'bonding', 'leisure'] # aka my_df columns / rolling_avgs dict key values
i_i = [0, 1, 2, 3, 4, 5, 6] # indexer
i_s = 0 # start slice indexer
i_e = 12 # end slice endexer

for i in i_i:
  while i_e <= 320:

  # dict to capture the averages as values and emotion as keys
  rolling_avg[ emotions[i] ] = np.mean(my_df[emotions[i]].iloc[i_s:i_e])


  i_s += 10
  i_e += 10
Digital Moniker
  • 281
  • 1
  • 12

0 Answers0