Horje
pandas calculate iqr Code Example
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)




Python

Related
higlight words in python Code Example higlight words in python Code Example
element wise subtraction python list Code Example element wise subtraction python list Code Example
funcions in python Code Example funcions in python Code Example
how to read numbers in csv files python Code Example how to read numbers in csv files python Code Example
regex to end with python Code Example regex to end with python Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9