Home > Mobile >  how to find mean in rows of dataframe?
how to find mean in rows of dataframe?

Time:07-12

df:

 A B  C D
 1 2  3 la
 0 1 -1 na

How to find mean each row like that?:

 A B  C  D  mean
 1 2  3  la    2
 0 1 -1  na    0

I try, but not the case(:

 some_col = [A,B,C]
 for col in some_col:
    df['mean'] = [np.mean([x, y]) for x, y in zip(df[col], df['mean'])]

CodePudding user response:

You should try this:

df.mean(axis=1)
  • Related