gpt4 book ai didi

python - Pandas 数据框 - 删除异常值

转载 作者:行者123 更新时间:2023-11-28 21:39:52 27 4
gpt4 key购买 nike

<分区>

给定一个 pandas 数据框,我想根据其中一列排除与异常值(Z 值 = 3)对应的行。

数据框看起来像这样:

df.dtypes
_id object
_index object
_score object
_source.address object
_source.district object
_source.price float64
_source.roomCount float64
_source.size float64
_type object
sort object
priceSquareMeter float64
dtype: object

对于行:

dff=df[(np.abs(stats.zscore(df)) < 3).all(axis='_source.price')]

引发了以下异常:

-------------------------------------------------------------------------    
TypeError Traceback (most recent call last)
<ipython-input-68-02fb15620e33> in <module>()
----> 1 dff=df[(np.abs(stats.zscore(df)) < 3).all(axis='_source.price')]

/opt/anaconda3/lib/python3.6/site-packages/scipy/stats/stats.py in zscore(a, axis, ddof)
2239 """
2240 a = np.asanyarray(a)
-> 2241 mns = a.mean(axis=axis)
2242 sstd = a.std(axis=axis, ddof=ddof)
2243 if axis and mns.ndim < a.ndim:

/opt/anaconda3/lib/python3.6/site-packages/numpy/core/_methods.py in _mean(a, axis, dtype, out, keepdims)
68 is_float16_result = True
69
---> 70 ret = umr_sum(arr, axis, dtype, out, keepdims)
71 if isinstance(ret, mu.ndarray):
72 ret = um.true_divide(

TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'

以及返回值

np.isreal(df['_source.price']).all()

True

为什么会出现上述异常,如何排除异常值?

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com