Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to find outliers in python

# outlier detection function
def outlier(col:str, df_:pd.DataFrame=df, remove:bool=False) -> list:
    """This function calculates the upper and lower fence
    of any column and can also remove from the dataset"""
    q1 = df_[col].quantile(0.25)
    q3 = df_[col].quantile(0.75)
    
    iqr = q3-q1
    lower_fence = q1 - iqr*1.5
    upper_fence = q3 + iqr*1.5

    if remove:
        temp = df_[(df_[col] > lower_fence) & (df_[col] < upper_fence)]
        return temp

    return [lower_fence, upper_fence]
Comment

PREVIOUS NEXT
Code Example
Python :: print from 1 to n in python 
Python :: numpy roundup to nearest 5 
Python :: logistic regression algorithm in python 
Python :: how to read excel with multiple pages on pandas 
Python :: loop through 2 items python 
Python :: df = df.reset_index(level=0) 
Python :: python push to dataframe pandas 
Python :: how to install whl file in python 
Python :: get first row sqlalchemy 
Python :: Converting List to Dataframe Using zip() function 
Python :: fastapi json request 
Python :: returns the smallest positive integer python 
Python :: how to create a label in python 
Python :: install python in centos7 
Python :: plot sphere in matplotlib 
Python :: pandas Unnamed: 0 
Python :: title() function in python 
Python :: extend tuple python 
Python :: get time python 
Python :: panda3d 
Python :: python background function 
Python :: pandas dataframe crosstab 
Python :: curl in python 
Python :: print a formatted table using python 
Python :: print alphabets in python 
Python :: pandas write to excel 
Python :: initialize dictionary to zero in python 
Python :: file base name and extension python 
Python :: python repeting timer 
Python :: access google transalte pandas 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =