Is there function that can remove the outliers?

前端 未结 4 930
生来不讨喜
生来不讨喜 2021-01-19 10:17

I find a function to detect outliers from columns but I do not know how to remove the outliers

is there a function for excluding or removing outliers from the colum

4条回答
  •  北恋
    北恋 (楼主)
    2021-01-19 10:44

    An easy solution would be to use scipy.stats.zscore

    from scipy.stats import zscore
    # calculates z-score values
    df["zscore"] = zscore(df["Pre_TOTAL_PURCHASE_ADJ"]) 
    
    # creates `is_outlier` column with either True or False values, 
    # so that you could filter your dataframe accordingly
    df["is_outlier"] = df["zscore"].apply(lambda x: x <= -1.96 or x >= 1.96)
    

提交回复
热议问题