Remove outliers with median value and Capping
# Removing outliers by standard methods and Plotting graphs: for col in ['lead_time','adr','days_in_waiting_list']: # Using IQR method and capping to define the range of inliners: lower_cap, q1, q3, upper_cap, median = df[col].quantile([0.01,0.25,0.75,0.99,0.5]) lower_limit = q1 - 1.5*(q3-q1) upper_limit = q3 + 1.5*(q3-q1) # Replacing Outliers with median value and Capping new_df[col] = np.where(new_df[col] > upper_limit, median,np.where( new_df[col] < lower_limit,median,np.where( new_df[col] < lower_cap,lower_cap,np.where( new_df[col] > upper_cap,upper_cap,new_df[col]))))