【问题标题】:Identifying outliers in a python Dataframe识别python数据框中的异常值
【发布时间】:2021-12-10 14:18:33
【问题描述】:

我试图在我的集群模型中识别具有标准偏差的异常值。

# calculate summary statistics
rfm_mean, rfm_std = mean(rfm), std(rfm)

# identify outliers
cut_off = rfm_std * 3
lower, upper = rfm_mean - cut_off, rfm_mean + cut_off

# identify outliers
outliers = [x for x in rfm if x < lower or x > upper]
print('Identified outliers: %d' % len(outliers))

不知道为什么我会收到此回溯错误;

Invalid comparison between dtype=float64 and str

对此的任何帮助将不胜感激。

提前感谢您的支持!

【问题讨论】:

  • 如果没有数据和摘要或数据类型的 sn-p,社区就无法知道那里有什么问题。不知道你在那里实际比较了什么。

标签: python dataframe hierarchical-clustering outliers


【解决方案1】:

您不能比较 float64 和字符串。这可能发生在这里:

outliers = [x for x in rfm if x < lower or x > upper]

在使用比较运算符之前使用 DataFrame.astype(dtype, copy=True, errors='raise') 转换为正确的类型

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.astype.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-20
    • 1970-01-01
    • 2015-09-28
    • 2021-03-24
    • 2021-02-09
    • 2016-06-10
    • 2011-01-06
    • 2016-05-10
    相关资源
    最近更新 更多