how to sort values of pandas dataframe for iqr

Solutions on MaxInterview for how to sort values of pandas dataframe for iqr by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "how to sort values of pandas dataframe for iqr"
Jedediah
20 Jun 2020
1    def mod_outlier(df):
2        df1 = df.copy()
3        df = df._get_numeric_data()
4
5
6        q1 = df.quantile(0.25)
7        q3 = df.quantile(0.75)
8
9        iqr = q3 - q1
10
11        lower_bound = q1 -(1.5 * iqr) 
12        upper_bound = q3 +(1.5 * iqr)
13
14
15        for col in col_vals:
16            for i in range(0,len(df[col])):
17                if df[col][i] < lower_bound[col]:            
18                    df[col][i] = lower_bound[col]
19
20                if df[col][i] > upper_bound[col]:            
21                    df[col][i] = upper_bound[col]    
22
23
24        for col in col_vals:
25            df1[col] = df[col]
26
27        return(df1)