DataFrame.quantile ()API介绍说明

本文详细介绍了Pandas库中DataFrame.quantile()函数的使用方法,包括参数解释:q值定义、轴方向选择、是否仅限数值型数据、插值方法等。并阐述了返回值类型,当q为数组时返回DataFrame,q为浮点数时返回Series。

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

DataFrame.quantile(self, q=0.5, axis=0, numeric_only=True, interpolation=‘linear’)

Return values at the given quantile over requested axis.

Parameters:

q : float or array-like, default 0.5 (50% quantile)
Value between 0 <= q <= 1, the quantile(s) to compute.

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

numeric_only : bool, default True
If False, the quantile of datetime and timedelta data will be computed as well.

interpolation : {‘linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest’}
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.
New in version 0.18.0.

Returns:

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.
D:\anaconda3\python.exe "D:\PycharmProjects\PythonProject\BH 优快云02.py" 正在加载数据... 正在进行异常值处理... 处理特征: CRIM D:\PycharmProjects\PythonProject\BH 优快云02.py:54: UserWarning: Glyph 22788 (\N{CJK UNIFIED IDEOGRAPH-5904}) missing from font(s) DejaVu Sans. plt.tight_layout() D:\PycharmProjects\PythonProject\BH 优快云02.py:54: UserWarning: Glyph 29702 (\N{CJK UNIFIED IDEOGRAPH-7406}) missing from font(s) DejaVu Sans. plt.tight_layout() D:\PycharmProjects\PythonProject\BH 优快云02.py:54: UserWarning: Glyph 21069 (\N{CJK UNIFIED IDEOGRAPH-524D}) missing from font(s) DejaVu Sans. plt.tight_layout() D:\PycharmProjects\PythonProject\BH 优快云02.py:54: UserWarning: Glyph 21518 (\N{CJK UNIFIED IDEOGRAPH-540E}) missing from font(s) DejaVu Sans. plt.tight_layout() D:\PycharmProjects\PythonProject\BH 优快云02.py:55: UserWarning: Glyph 22788 (\N{CJK UNIFIED IDEOGRAPH-5904}) missing from font(s) DejaVu Sans. plt.savefig(f'iqr_{column}.png', bbox_inches='tight') D:\PycharmProjects\PythonProject\BH 优快云02.py:55: UserWarning: Glyph 29702 (\N{CJK UNIFIED IDEOGRAPH-7406}) missing from font(s) DejaVu Sans. plt.savefig(f'iqr_{column}.png', bbox_inches='tight') D:\PycharmProjects\PythonProject\BH 优快云02.py:55: UserWarning: Glyph 21069 (\N{CJK UNIFIED IDEOGRAPH-524D}) missing from font(s) DejaVu Sans. plt.savefig(f'iqr_{column}.png', bbox_inches='tight') D:\PycharmProjects\PythonProject\BH 优快云02.py:55: UserWarning: Glyph 21518 (\N{CJK UNIFIED IDEOGRAPH-540E}) missing from font(s) DejaVu Sans. plt.savefig(f'iqr_{column}.png', bbox_inches='tight') 处理特征: ZN D:\PycharmProjects\PythonProject\BH 优快云02.py:54: UserWarning: Glyph 22788 (\N{CJK UNIFIED IDEOGRAPH-5904}) missing from font(s) DejaVu Sans. plt.tight_layout() D:\PycharmProjects\PythonProject\BH 优快云02.py:54: UserWarning: Glyph 29702 (\N{CJK UNIFIED IDEOGRAPH-7406}) missing from font(s) DejaVu Sans. plt.tight_layout() D:\PycharmProjects\PythonProject\BH 优快云02.py:54: UserWarning: Glyph 21069 (\N{CJK UNIFIED IDEOGRAPH-524D}) missing from font(s) DejaVu Sans. plt.tight_layout() D:\PycharmProjects\PythonProject\BH 优快云02.py:54: UserWarning: Glyph 21518 (\N{CJK UNIFIED IDEOGRAPH-540E}) missing from font(s) DejaVu Sans. plt.tight_layout() D:\PycharmProjects\PythonProject\BH 优快云02.py:55: UserWarning: Glyph 22788 (\N{CJK UNIFIED IDEOGRAPH-5904}) missing from font(s) DejaVu Sans. plt.savefig(f'iqr_{column}.png', bbox_inches='tight') D:\PycharmProjects\PythonProject\BH 优快云02.py:55: UserWarning: Glyph 29702 (\N{CJK UNIFIED IDEOGRAPH-7406}) missing from font(s) DejaVu Sans. plt.savefig(f'iqr_{column}.png', bbox_inches='tight') D:\PycharmProjects\PythonProject\BH 优快云02.py:55: UserWarning: Glyph 21069 (\N{CJK UNIFIED IDEOGRAPH-524D}) missing from font(s) DejaVu Sans. plt.savefig(f'iqr_{column}.png', bbox_inches='tight') D:\PycharmProjects\PythonProject\BH 优快云02.py:55: UserWarning: Glyph 21518 (\N{CJK UNIFIED IDEOGRAPH-540E}) missing from font(s) DejaVu Sans. plt.savefig(f'iqr_{column}.png', bbox_inches='tight') 处理特征: INDUS D:\PycharmProjects\PythonProject\BH 优快云02.py:54: UserWarning: Glyph 22788 (\N{CJK UNIFIED IDEOGRAPH-5904}) missing from font(s) DejaVu Sans. plt.tight_layout() D:\PycharmProjects\PythonProject\BH 优快云02.py:54: UserWarning: Glyph 29702 (\N{CJK UNIFIED IDEOGRAPH-7406}) missing from font(s) DejaVu Sans. plt.tight_layout() D:\PycharmProjects\PythonProject\BH 优快云02.py:54: UserWarning: Glyph 21069 (\N{CJK UNIFIED IDEOGRAPH-524D}) missing from font(s) DejaVu Sans. plt.tight_layout() D:\PycharmProjects\PythonProject\BH 优快云02.py:54: UserWarning: Glyph 21518 (\N{CJK UNIFIED IDEOGRAPH-540E}) missing from font(s) DejaVu Sans. plt.tight_layout() D:\PycharmProjects\PythonProject\BH 优快云02.py:55: UserWarning: Glyph 22788 (\N{CJK UNIFIED IDEOGRAPH-5904}) missing from font(s) DejaVu Sans. plt.savefig(f'iqr_{column}.png', bbox_inches='tight') D:\PycharmProjects\PythonProject\BH 优快云02.py:55: UserWarning: Glyph 29702 (\N{CJK UNIFIED IDEOGRAPH-7406}) missing from font(s) DejaVu Sans. plt.savefig(f'iqr_{column}.png', bbox_inches='tight') D:\PycharmProjects\PythonProject\BH 优快云02.py:55: UserWarning: Glyph 21069 (\N{CJK UNIFIED IDEOGRAPH-524D}) missing from font(s) DejaVu Sans. plt.savefig(f'iqr_{column}.png', bbox_inches='tight') D:\PycharmProjects\PythonProject\BH 优快云02.py:55: UserWarning: Glyph 21518 (\N{CJK UNIFIED IDEOGRAPH-540E}) missing from font(s) DejaVu Sans. plt.savefig(f'iqr_{column}.png', bbox_inches='tight') 处理特征: CHAS Traceback (most recent call last): File "D:\PycharmProjects\PythonProject\BH 优快云02.py", line 65, in <module> df[col] = iqr_outlier_processing(df, col) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\PycharmProjects\PythonProject\BH 优快云02.py", line 25, in iqr_outlier_processing Q1 = df[column].quantile(0.25) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda3\Lib\site-packages\pandas\core\series.py", line 2887, in quantile result = df.quantile(q=q, interpolation=interpolation, numeric_only=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda3\Lib\site-packages\pandas\core\frame.py", line 12146, in quantile res_df = self.quantile( ^^^^^^^^^^^^^^ File "D:\anaconda3\Lib\site-packages\pandas\core\frame.py", line 12191, in quantile res = data._mgr.quantile(qs=q, interpolation=interpolation) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda3\Lib\site-packages\pandas\core\internals\managers.py", line 1549, in quantile blk.quantile(qs=qs, interpolation=interpolation) for blk in self.blocks ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda3\Lib\site-packages\pandas\core\internals\blocks.py", line 1891, in quantile result = quantile_compat(self.values, np.asarray(qs._values), interpolation) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda3\Lib\site-packages\pandas\core\array_algos\quantile.py", line 41, in quantile_compat return values._quantile(qs, interpolation) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda3\Lib\site-packages\pandas\core\arrays\_mixins.py", line 519, in _quantile res_values = self._cast_quantile_result(res_values) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda3\Lib\site-packages\pandas\core\arrays\categorical.py", line 2480, in _cast_quantile_result assert res_values.dtype == self._ndarray.dtype ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AssertionError 进程已结束,退出代码为 1
最新发布
06-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值