shovene
unknown
python
2 years ago
687 B
18
Indexable
import math
def shovene(self, column, max_iter=5):
iter_count = 0
while iter_count < max_iter:
n = self.df[column].count()
mean = self.df[column].mean()
std = self.df[column].std()
outliers_indices = []
for idx, elem in enumerate(self.df[column]):
if std == 0: # чтобы предотвратить деление на 0
break
if math.erfc((abs(elem - mean)) / std) < 1 / (2 * n):
outliers_indices.append(idx)
if not outliers_indices:
break
self.df = self.df.drop(index=outliers_indices)
iter_count += 1
return self.df
Editor is loading...