Is it possible to add "range" (ie.max-min) to the pandas describe function in python?

时间:2018-02-03 08:28:51

标签: python pandas

Is it possible to add "range" (ie.max-min) to the pandas describe function in python?

I would like to get like this ?

     sepal_length   sepal_width
count    150            150
mean     5.843333       3.054
std      0.828066       0.433594
min      4.3            2
25%      5.1            2.8
50%      5.8            3
75%      6.4            3.3
max      7.9            4.4
Range    3.6            2.4

1 个答案:

答案 0 :(得分:2)

I think simpliest is add to output subtracting rows and wrap to function:

def describe_new(df):
    df1 = df.describe()
    df1.loc["range"] = df1.loc['max'] - df1.loc['min']
    return df1

print (describe_new(df))