0

I have a dictionary of dataframes:

{1 : df1, 2 : df2 .. }

All dataframe are with the same shapes. (but different number of rows). I want to create the dataframe where every column is the mean of this column for this row. So if:

df1 : A  B  C
      2  4  6
      1  3  5
df2 : A  B  C
      0  2  8
      7  9  5

I will get:

new_df:  A  B  C 
         1  3  7
         4  6  5

What is the best way to do so?

Cranjis
  • 1,590
  • 8
  • 31
  • 64

1 Answers1

2

Try via concat() and mean():

out=pd.concat(d.values()).mean(level=0)

OR

out=pd.concat(d).mean(level=1)

Note: here d is your dictionary of dataframes

output of out:

    A   B   C
0   1   3   7
1   4   6   5
Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41