[Python] Remove outliers using groupby in data with several categories

Discussão em 'Python' iniciado por Stack, Abril 24, 2025.

  1. Stack

    Stack Membro Participativo

    I have a time-series with several products. I want to remove outliers using the Tukey Fence method. The idea is to create a column with a flag indicating outlier or not, using groupby. It should be like that (flag column is added by the groupby):

    date prod units flag
    1 a 100 0
    2 a 90 0
    3 a 80 0
    4 a 15 1
    1 b 200 0
    2 b 180 0
    3 b 190 0
    4 b 30000 1


    I was able to do it separating the prods using a for-loop and then making corresponding joins, but I wish to do it more cleanly.

    Continue reading...

Compartilhe esta Página