Guest User

Untitled

a guest
Jan 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. # Write a function to remove outliers using IQR
  2. def outliers_IQR(data, col):
  3. lower_quartile = data[col].quantile(0.25)
  4. upper_quartile = data[col].quantile(0.75)
  5. IQR = upper_quartile - lower_quartile
  6. outlier_thresh = 1.5 * IQR
  7. return data[data[col].between((lower_quartile - outlier_thresh), (upper_quartile + outlier_thresh))]
  8.  
  9. autos_IQR = outliers_IQR(autos, 'price_dollar')
  10. autos_IQR = outliers_IQR(autos_IQR, 'odometer_km')
Add Comment
Please, Sign In to add comment