How Can I Impute Values To Outlier Cells Based On Groups?
I have a pandas dataframe with some values #| X | Y | Value1 | Value2 | --------------------------- 1| 2 | 4 | 10 | 3 | 2| 2 | 4 | 3 | 2 | 3| 2 | 4 | 1 |
Solution 1:
Using the following answer from n1k31t4 in: https://datascience.stackexchange.com/questions/37717/imputation-missing-values-other-than-using-mean-median-in-python I was able to solve my problem.
df[col]=df.groupby(['X', 'Y'])[col].transform(lambda x: x.median() if (np.abs(x)>3).any() else x)
Post a Comment for "How Can I Impute Values To Outlier Cells Based On Groups?"