Add column to the end of Pandas DataFrame containing average of previous data

前端 未结 4 1279
深忆病人
深忆病人 2021-02-12 14:04

I have a DataFrame ave_data that contains the following:

ave_data

Time        F7           F8            F9  
00:00:00    43.005593    -56.509746           


        
4条回答
  •  别那么骄傲
    2021-02-12 14:52

    In common case if you would like to use specific columns, you can use:

    df['average'] = df[['F7','F8']].mean(axis=1)
    

    where axis=1 stands for rowwise action (using column values for each row to calculate the mean in 'average' column)

    Then you may want to sort by this column:

    df.sort_values(by='average',ascending=False, inplace=True)
    

    where inplace=True stands for applying action to dataframe instead of calculating on the copy.

提交回复
热议问题