Search code examples
pandascsvrow

calculate average of the velocity in pandas


Please give advice. I am newbie in python. I have data looks like this

df
ID  V1  V2  V3  V4  V5
ID1  2  4   6   8   10
ID2  3  5   7   7   9
ID3  4  6   3   6   8
ID4  5  7   4   5   7
ID5  6  8   5   4   6
ID6  7  9   6   3   5
ID7  8  2   8   2   4
ID8  9  2   7   6   3
ID9  8  4   4   7   6
ID10 9  5   4   8   9

I want to analyze average of the data with this equation.

rar

I used this code:

result['Mean'] = result.mean(numeric_only=True, axis=1)

I dont know this is good or not.


Solution

  • Since you did not provide the expected output , base on your equation

    s=df.iloc[:,1:]
    s.shape[1]/(1/s).sum(1)
    0    4.379562
    1    5.375427
    2    4.800000
    3    5.343511
    4    5.504587
    5    5.241265
    6    3.333333
    7    3.987342
    8    5.350318
    9    6.271777
    dtype: float64