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 :: django admin create superuser 
Python :: how to import pygame onto python 
Python :: dictionary from two lists 
Python :: drop unnamed column pandas 
Python :: access the value in settings django 
Python :: how to export a string as txt file in python 
Python :: how to make a custom icon for pygame 
Python :: hibernate windows with python 
Python :: python repeat every n seconds 
Python :: python dlete folder 
Python :: python delete saved image 
Python :: python read xlsb pandas 
Python :: shapely polygon from string 
Python :: pickle a dictionary 
Python :: export file csv 
Python :: unzip file python 
Python :: python current date 
Python :: python alert 
Python :: parse datetime python 
Python :: convert column string to int pandas 
Python :: python tkinter underline text 
Python :: Package python3-pip is not available, but is referred to by another package. 
Python :: selenium python get innerhtml 
Python :: python string argument without an encoding 
Python :: export pandas dataframe as excel 
Python :: convert pandas dataframe to spark dataframe 
Python :: python: change column name 
Python :: join video moviepy 
Python :: time decorator python 
Python :: correlation between lists python 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =