I have a DataFrame and I am trying to deal with outliers. I used boxplots to visually detect them and tried to apply a correction that does seem to work but doesn't really.
So I tried the following code which seems to work but when I display the boxplotsplots again (to check that the changes have been applied), some variables still have outliers which confuses me :
for col in dfint.columns:
#Quartiles
Q1=np.quantile(dfint[col], q=0.25)
Q3=np.quantile(dfint[col], q=0.75)
IQR=Q3-Q1
#Median
median=st.median(dfint[col])
dfint[col]=np.where(dfint[col]>median+1.5*IQR, median+1.5*IQR,
np.where(dfint[col]<median-1.5*IQR, median-1.5*IQR, dfint[col]))
Is there someting wrong in this code or with my method. Can I rely on Boxplots ? Thanks for your help.