title: How to calculate modified Z score and IQR on each column of the dataframe
body: <p>I have a data frame and i am trying to clean the data before my analysis.</p>
  
  <p>I am putting a sample data for trial as my data is bit complex.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>A   B  C D
  30 24 13 41
  30 25 14 45
  30 27 15 44
  30 28 16 43
  31 21 12 4
  31 2  17 99
  3 89 99 45
  78 24 0   43
  35 252 12 45
  36 23 13 44</code></pre>
  </div>
  </div>
  </p>
  
  <p>I am trying to deal with the outliers and trying to calculate the Modified Z score (median one) and IQR for filtering out the outliers from the data so that i can get the quality data for further analysis.</p>
  
  <p>I want to calculate IQR and then Z score for each column and filter out the outliers for each column in the data frame.</p>
  
  <p>I have tried few things till now like:</p>
  
  <p>IQR:</p>
  
  <pre class="lang-py prettyprint-override"><code>
  for col in df2.columns:
      col = np.array([col])
      q1_a = np.percentile(col, 25)
      q3_a = np.percentile(col, 75)
      iqr1 = q3_a - q1_a
      print(iqr1)
  </code></pre>
  
  <p>Modified Z score:</p>
  
  <pre class="lang-py prettyprint-override"><code>
  for col in df2.columns:
      threshold = 3.5
      col_zscore = col +'_zscore'
      median_y = df[col].median()
      print(median_y)
      median_absolute_deviation_y = (np.abs(df2[col] - median_y)).median()
      print(median_absolute_deviation_y)
      modified_z_scores = 0.7413 *((df2[col] - median_y)/median_absolute_deviation_y)
      print(modified_z_scores)
      df2[col_zscore] = np.abs(modified_z_scores)
  
  df2 = df2[(np.abs(df2[col_zscore]) &lt; 3.5).all(axis=1)]
  print(df2)
  
  </code></pre>
  
  <p>But not getting the right answer. The function does not apply on each column and create the dataframe of my intention at the end.
  Please help.
  Thanks.</p>