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?

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.