Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas remove outliers for multiple columns

def cap_data(df):
    for col in df.columns:
        print("capping the ",col)
        if (((df[col].dtype)=='float64') | ((df[col].dtype)=='int64')):
            percentiles = df[col].quantile([0.01,0.99]).values
            df[col][df[col] <= percentiles[0]] = percentiles[0]
            df[col][df[col] >= percentiles[1]] = percentiles[1]
        else:
            df[col]=df[col]
    return df

final_df=cap_data(df)
Comment

PREVIOUS NEXT
Code Example
Python :: compress image pillow 
Python :: python package version 
Python :: python dict append value 
Python :: how to install neat 
Python :: error handling flask 
Python :: multiprocessing a for loop python 
Python :: python operators 
Python :: how to create numpy array using two vectors 
Python :: remove env variable python 
Python :: make a script run itself again python 
Python :: pandas replace values based on condition 
Python :: python dict key delete 
Python :: django models.py convert DateTimeField to DateField 
Python :: tkinter get child in frame 
Python :: how to check if an object of a certain type python 
Python :: numpy combinations of 5 bits 
Python :: Double-Linked List Python 
Python :: shutdown flask server with request 
Python :: django never_cache example 
Python :: python random liste 
Python :: plot second y axis matplotlib 
Python :: complex arrays python 
Python :: colab version python 
Python :: multiline comment python 
Python :: tensorflow bert implementation 
Python :: python get list memory size 
Python :: filter query objects by date range in Django? 
Python :: colorbar font size python 
Python :: dict typing python 
Python :: how to simplify fraction in python 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =