我正在尝试使用zscore从数据集中删除离群值。仅是我的一列,“金额”是数字,因此如果“金额”包含归类为异常值的数字,我想删除整行。这是我的代码,我将整个数据集称为“数据”
'''#Change 'Amount' data to numeric
Data['Amount'] = pd.to_numeric(Data['Amount'])
#Calculating and printing zscore
z = np.abs(stats.zscore(Data['Amount']))
print(z)
#Identifying and printing the outliers
threshold = 3
print(np.where(z > 3))
#Removing the outliers
Data = Data[Data['Amount'][(z < 3).all()]]
'''
这里出现错误:在pandas._libs.index.IndexEngine.get_value中的文件“ pandas_libs \ index.pyx”,第81行在pandas._libs.index.IndexEngine.get_value中的文件“ pandas_libs \ index.pyx”,第89行在pandas._libs.index.IndexEngine.get_loc中的文件“ pandas_libs \ index.pyx”,第129行在pandas._libs.index.Int64Engine._check_type中的文件“ pandas_libs \ index_class_helper.pxi”,第91行KeyError:False
我不明白为什么会收到此错误,该错误发生在代码的最后一行。有没有更好,更轻松的方法来删除异常值