必须整得明明白白——pandas df.quantile()

pd.DataFrame(np.array([[1, 1], [2, 10], [3, 100], [4, 100]]),
columns=[‘a’, ‘b’]).quantile([.1,.2,.3,.4, .5,.6,.7,.8])
a b
0.1 1.3 3.7
0.2 1.6 6.4
0.3 1.9 9.1
0.4 2.2 28.0
0.5 2.5 55.0
0.6 2.8 82.0
0.7 3.1 100.0
0.8 3.4 100.0
总的行数为n,
分位数参数为p,

天才第一步计算pos:

  (n-1)*p的结果中整数部分a,   小数部分为b
  pos = a+1

step2:

  最终的结果为df[pos]+(df[pos+1]-df[index])*b

不信你试试?

猜你喜欢

转载自blog.csdn.net/weixin_38246633/article/details/86655212