Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas calculate iqr

# Removing the outliers
def removeOutliers(data, col):
    Q3 = np.quantile(data[col], 0.75)
    Q1 = np.quantile(data[col], 0.25)
    IQR = Q3 - Q1
 
    print("IQR value for column %s is: %s" % (col, IQR))
    global outlier_free_list
    global filtered_data
 
    lower_range = Q1 - 1.5 * IQR
    upper_range = Q3 + 1.5 * IQR
    outlier_free_list = [x for x in data[col] if (
        (x > lower_range) & (x < upper_range))]
    filtered_data = data.loc[data[col].isin(outlier_free_list)]
 
 
for i in data.columns:
      if i == data.columns[0]:
      removeOutliers(data, i)
    else:
      removeOutliers(filtered_data, i)
 
  
# Assigning filtered data back to our original variable
data = filtered_data
print("Shape of data after outlier removal is: ", data.shape)
Comment

PREVIOUS NEXT
Code Example
Python :: python decouple default value 
Python :: penggunaan fromkeys di python 
Python :: Python pattern of 1010101 
Python :: Use PIP from inside script 
Python :: Remove Brackets from List Using the * operator with the Separator method 
Python :: celery 5.2.3 decorators 
Python :: list python !g 
Python :: QDateEdit.date().toString("MMMM dd, yyyy") does not display months in English 
Python :: How to use a <ComboboxSelected virtual event with tkinter 
Python :: gremlin python import 
Python :: list average python recursion 
Python :: pixel accuracy image segmentation python 
Python :: heatmap colorbar label 
Python :: gitlab ci deploy key 
Python :: Flask_SQLAlchemy is claiming my value is not boolean 
Python :: Flask - how do I combine Flask-WTF and Flask-SQLAlchemy to edit db models 
Python :: how to make a typing effect in python 
Python :: for y in range(10): for x in range(y): print("*",end=') print() 
Python :: how to close python in terminal 
Python :: print all gpu available tensor 
Python :: ring Trace library usage to pass an error 
Python :: python adx indicator 
Python :: python loc id in list 
Python :: how to know google index of a page using python 
Python :: how to split string into list conditionally+python 
Python :: tens place in digit 
Python :: how to load images from folder in python 
Python :: modeltranslation 
Python :: how to add multiple commands to tkinter button 
Python :: can I activate a function inside the definition of the same function 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =