quantile() 函数

本文介绍了Python中的quantile()函数,用于计算指定的分位数。重点讲解了参数q、axis和interpolation的含义,以及四分位数的概念,包括Q1、Q2(中位数)和Q3,并提到了四分位距IQR的重要性。此外,还解释了不同插值方法对分位数计算的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Series. quantile ( q=0.5interpolation='linear' )

Parameters:

q : float or array-like, default 0.5 (50% quantile)

0 <= q <= 1, the quantile(s) to compute

interpolation : {‘linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest’}

New in version 0.18.0.

This optional parameter specifies the interpolation method to use, when the desired quantile lies between two data points i and j:

  • linear: i + (j - i) * fraction, where fraction is the fractional part of the index surrounded by i and j.
  • lower: i.
  • higher: j.
  • nearest: i or j whichever is nearest.
  • midpoint: (i + j) / 2.
Returns:

quantile : float or Series

if q is an array, a Series will be returned where the index is q and the values are the quantiles.

- q : float or array-like, default 0.5 (50% quantile 即中位数-第2四分位数)
0 <= q <= 1, the quantile(s) to compute


- axis : {0, 1, ‘index’, ‘columns’} (default  0)
0 or ‘index’ for row-wise, 1 or ‘columns’ for column-wise

- interpolation(插值方法) : {‘linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest’}

当选中的分为点位于两个数数据点 i and j 之间时:
    linear: i + (j - i) * fraction, fraction由计算得到的pos的小数部分(可以通过下面一个例子来理解这个fraction);
    lower: i.
    higher: j.
    nearest: i or j whichever is nearest.

    midpoint: (i + j) / 2.

统计学上的四分为函数

原则上q是可以取0到1之间的任意值的。但是有一个四分位数是q分位数中较为有名的。

所谓四分位数;即把数值由小到大排列并分成四等份,处于三个分割点位置的数值就是四分位数。

  • 第1四分位数 (Q1),又称“较小四分位数”,等于该样本中所有数值由小到大排列后第25%的数字。
  • 第2四分位数 (Q2),又称“中位数”,等于该样本中所有数值由小到大排列后第50%的数字。
  • 第3四分位数 (Q3),又称“较大四分位数”,等于该样本中所有数值由小到大排列后第75%的数字。

第3四分位数与第1四分位数的差距又称四分位距(InterQuartile Range,IQR)

当q=0.25 0.5 0.75 时,就是在计算四分位数。

Return value at the given quantile, a la numpy.percentile

DataFrame. quantile ( q=0.5axis=0numeric_only=True )

Parameters:

q : float or array-like, default 0.5 (50% quantile)

0 <= q <= 1, the quantile(s) to compute

axis : {0, 1, ‘index’, ‘columns’} (default 0)

0 or ‘index’ for row-wise, 1 or ‘columns’ for column-wise

Returns:

quantiles : Series or DataFrame

If q is an array, a DataFrame will be returned where the index is q, the columns are the columns of self, and the values are the quantiles. If q is a float, a Series will be returned where the index is the columns of self and the values are the quantiles.

Return values at the given quantile over requested axis, a la numpy.percentile.

相关阅读:

https://www.zhihu.com/question/58421946

.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weay

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值