13
$\begingroup$

I have data of a metric grouped date wise. I have plotted the data, now, how do I remove the values outside the range of the boxplot (outliers)?

All the ['AVG'] data is in a single column, I need it for time series modelling.

enter image description here

$\endgroup$

3 Answers 3

17
$\begingroup$

Seaborn uses inter-quartile range to detect the outliers. What you need to do is to reproduce the same function in the column you want to drop the outliers. It's quite easy to do in Pandas.

If we assume that your dataframe is called df and the column you want to filter based AVG, then

Q1 = df['AVG'].quantile(0.25)
Q3 = df['AVG'].quantile(0.75)
IQR = Q3 - Q1    #IQR is interquartile range. 

filter = (df['AVG'] >= Q1 - 1.5 * IQR) & (df['AVG'] <= Q3 + 1.5 *IQR)
df.loc[filter]  
$\endgroup$
3
  • $\begingroup$ KeyError: 'AVG' $\endgroup$
    – Leos313
    Oct 15, 2020 at 9:13
  • 1
    $\begingroup$ Probably you don’t have that column. The OP had a column called AVG $\endgroup$
    – Tasos
    Oct 15, 2020 at 15:07
  • $\begingroup$ right, I do not! Now, I know what to look for! Thank you $\endgroup$
    – Leos313
    Oct 15, 2020 at 15:16
14
$\begingroup$

If you need to remove outliers and you need it to work with grouped data, without extra complications, just add showfliers argument as False in the function call. It's inherited from matplotlib.

showfliers=False
$\endgroup$
0
$\begingroup$

You can simply turn showfliers = False in seaborn.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.