答案 0 :(得分:2)
如果data
是您的一维数据(例如数字列表),则可以这样删除离群值:
import numpy as np
a = np.array(data)
q75, q25 = np.percentile(a, [75 ,25])
iqr = q75 - q25
min = q25 - (iqr*1.5) # elements below min are outliers
max = q75 + (iqr*1.5) # elements above max are outliers
a_new = a[(a > min) & (a < max)] # a_new is your data with outliers removed