python - 删除特定列中的异常值

标签 python python-3.x dataframe outliers

我有一个名为 bids_data 的数据框

出价数据:

  Supplier_ID  shiper_RFQ
----------
0    2305      5000
1    2309      5200
2    2305      6500 
3    2307      4500
4    2301      900
5    2302      10000
6    2306      4500

我想从shiper_RFQ中删除异常值行并将它们存储在另一个数据框中。我尝试将 Shiper_RFQ 转换为列表,然后查找异常值,但效果不佳。

最佳答案

如果您有良好的数据,则使用threshold = 0.5

threshold = 1
print(df[df['shiper_RFQ'].apply(lambda x: np.abs(x - df['shiper_RFQ'].mean()) / df['shiper_RFQ'].std() < threshold)])

还有这个

 df = df[ np.abs(df['shiper_RFQ'] - df['shiper_RFQ'].mean()) / df['shiper_RFQ'].std() < threshold]

两者都会有相同的结果

输出

   Supplier_ID  shiper_RFQ
0         2305        5000
1         2309        5200
2         2305        6500
3         2307        4500
6         2306        4500

如果你打印你可以看到异常

print(df['shiper_RFQ'].apply(lambda x: np.abs(x - df['shiper_RFQ'].mean()) / df['shiper_RFQ'].std()))

0    0.084182
1    0.010523
2    0.468261
3    0.268329
4    1.594192
5    1.757294
6    0.268329

关于python - 删除特定列中的异常值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55255680/

相关文章:

python - 将 2 个 csv 文件与一个唯一列但不同的标题合并

python - 在 Python 中从 unicode 字符串中去除标点符号的最快方法

python - 如果另一列中的值匹配,如何填充列中的 nan 值

python - 根据教程fig不需要使用,但是在vscode中收到未使用的变量错误

r - 如何动态重命名数据帧的行?

python - 在 Linux 上安装 pyodbc 失败

python - 如何在Python中分割记录?

python - 为 pyenv + virtualenv 生成 python3-config

Python - 从 pandas 的聚合结果中获取组名称

python - 当两个数据框不相等时,如何根据它们中存在的单词加入两个数据框?