average of corresponding elements of a list of data frames

Viewed 687

I have a list of 3 data frames (same shape and same column names). I want to take the average of all the corresponding elements in each data frame.

df3 = pd.DataFrame(np.random.randn(8, 3), columns= ['M', 'N', 'O'])
df4 = pd.DataFrame(np.random.randn(8, 3), columns= ['M', 'N', 'O'])
df5 = pd.DataFrame(np.random.randn(8, 3), columns= ['M', 'N', 'O'])

Currently, I am planning to do it this way.

pd.DataFrame.add(df5, df4, df3)/3

But I have a whole bunch of dataframes coming in - let's say a list of 100 data frames. Please suggest a better way to approach this problem. Is there a way to do without looping them?

2 Answers
Related