I know my question sounds absurd but I dont know how else to put it, I want to drop rows with outliers in two different columns and some of the outliers are present in both columns so after I drop them in the first column it drops them fine but when I try to drop them in the second column I get error.
def outliers(data): # outliers using tukey fences
q1 = np.percentile(data, 25)
q3 = np.percentile(data, 75)
iqr = q3 - q1
upper = q3 + (1.5*iqr)
lower = q1 - (1.5*iqr)
return np.where((data>upper) | (data<lower))
height_outliers = newdf.iloc[outliers(newdf['height'])].index.values.tolist()
weight_outliers = newdf.iloc[outliers(newdf['weight'])].index.values.tolist()
newdf.drop(index = height_outliers, inplace = True)
newdf.drop(index = weight_outliers, inplace = True)
New contributor
Saad Kamboh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.