>>> df.quantile(numeric_only=True)
a 3.0
Name: 0.5, dtype: float64
>>> df.quantile()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/miniconda3/envs/dev/lib/python3.8/site-packages/pandas/core/frame.py", line 10887, in quantile
res_df = self.quantile( # type: ignore[call-overload]
File "/opt/miniconda3/envs/dev/lib/python3.8/site-packages/pandas/core/frame.py", line 10932, in quantile
res = data._mgr.quantile(qs=q, axis=1, interpolation=interpolation)
File "/opt/miniconda3/envs/dev/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 1587, in quantile
blocks = [
File "/opt/miniconda3/envs/dev/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 1588, in <listcomp>
blk.quantile(axis=axis, qs=qs, interpolation=interpolation)
File "/opt/miniconda3/envs/dev/lib/python3.8/site-packages/pandas/core/internals/blocks.py", line 1461, in quantile
result = quantile_compat(self.values, np.asarray(qs._values), interpolation)
File "/opt/miniconda3/envs/dev/lib/python3.8/site-packages/pandas/core/array_algos/quantile.py", line 37, in quantile_compat
return quantile_with_mask(values, mask, fill_value, qs, interpolation)
File "/opt/miniconda3/envs/dev/lib/python3.8/site-packages/pandas/core/array_algos/quantile.py", line 95, in quantile_with_mask
result = _nanpercentile(
File "/opt/miniconda3/envs/dev/lib/python3.8/site-packages/pandas/core/array_algos/quantile.py", line 216, in _nanpercentile
return np.percentile(
File "<__array_function__ internals>", line 5, in percentile
File "/opt/miniconda3/envs/dev/lib/python3.8/site-packages/numpy/lib/function_base.py", line 3867, in percentile
return _quantile_unchecked(
File "/opt/miniconda3/envs/dev/lib/python3.8/site-packages/numpy/lib/function_base.py", line 3986, in _quantile_unchecked
r, k = _ureduce(a, func=_quantile_ureduce_func, q=q, axis=axis, out=out,
File "/opt/miniconda3/envs/dev/lib/python3.8/site-packages/numpy/lib/function_base.py", line 3564, in _ureduce
r = func(a, **kwargs)
File "/opt/miniconda3/envs/dev/lib/python3.8/site-packages/numpy/lib/function_base.py", line 4112, in _quantile_ureduce_func
r = _lerp(x_below, x_above, weights_above, out=out)
File "/opt/miniconda3/envs/dev/lib/python3.8/site-packages/numpy/lib/function_base.py", line 4009, in _lerp
diff_b_a = subtract(b, a)
TypeError: unsupported operand type(s) for -: 'str' and 'str'
2条答案
按热度按时间z9smfwbn1#
在pandas版本2.0.0.中,
numeric_only
将其默认值更改为False,即mentioned in the docs。我试图在我的机器上重现你的警告(MacOS Ventura,Python 3.18.15),但没有得到任何警告或错误。
我可以确认,默认值是
False
。vvppvyoh2#
按
DataFrame.select_dtypes
选择数值列: