Flag Outliers In The Dataframe For Each Group
I would like to identify outliers for each group of values within a dataframe and return a dataframe with a column containing True/False for each row of the dataframe. data = {'Gro
Solution 1:
You can use groupby().transform
to get mean
and std
by group, then between
to find outliers:
groups = df.groupby('Group')
means = groups.Age.transform('mean')
stds = groups.Age.transform('std')
df['Flag'] = df.Age.between(means-stds*3, means+stds*3)
Post a Comment for "Flag Outliers In The Dataframe For Each Group"