Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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]))))
Comment

PREVIOUS NEXT
Code Example
Python :: Crop Image as Circle with transparent background 
Python :: deploy vue app to google cloud run 
Python :: REMINER VIA MAIL 
Python :: Access value 
Python :: stack overflow pop item from list in python 
Python :: datetime 
Python :: fill turtle python 3 
Python :: python autorun script 
Python :: save media file from url python 
Python :: if elif ladder in one line in python 
Python :: handling image files django aws 
Python :: python tkinter gui does not update until function completes 
Python :: how to remove hidden white spaces n columns 
Python :: scrapping components of webpage 
Python :: how to check if a function is callable in puyjom 
Python :: Calculate summary statistics across columns 
Python :: isclass function in python xml 
Python :: valueerror python list 
Python :: python backtest 
Python :: Find From Table Django 
Python :: reverse color matplotlib 
Python :: using ipfn in python 
Python :: checking time in time range 
Python :: python Find Hash 
Python :: generator expression python 
Python :: function print(text, times) 
Python :: is dictreader scoped in python 
Python :: adjusted price in crsp pandas 
Python :: how to delete blank rows from text file in spyder 
Python :: pandas resamples stratified by columns values 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =