title: Removing outlier from a single column
body: <p>I am removing outliers from a dataset. </p>
  
  <p>I decided to remove outlier from each column one-by-one. I have columns with a different number of missing values.</p>
  
  <p>I used this code but it removed the whole row containg the outlier and due to many NaN values in my data, number of rows of my data reduced drastically.</p>
  
  <pre class="lang-py prettyprint-override"><code>def remove_outlier(df_in, col_name):
      q1 = df_in[col_name].quantile(0.25)
      q3 = df_in[col_name].quantile(0.75)
      iqr = q3-q1 #Interquartile range
      fence_low  = q1-1.5*iqr
      fence_high = q3+1.5*iqr
      df_out = df_in.loc[(df_in[col_name] &gt; fence_low) &amp; (df_in[col_name] &lt; fence_high)]
      return df_out
  </code></pre>
  
  <p>Then I decided to remove outlier from each column, and fill ouliers with NaN in each column
  I wrote this code</p>
  
  <pre class="lang-py prettyprint-override"><code>def remove_outlier(df_in, col_name, thres=1.5):
      q1 = df_in[col_name].quantile(0.25)
      q3 = df_in[col_name].quantile(0.75)
      iqr = q3-q1 #Interquartile range
      fence_low  = q1-thres*iqr
      fence_high = q3+thres*iqr
      mask = (df_in[col_name] &gt; fence_high) &amp; (df_in[col_name] &lt; fence_low)
      df_in.loc[mask, col_name] = np.nan
      return df_in
  </code></pre>
  
  <p>But this code doesn't filters the outliers. gave the same result. </p>
  
  <p>What is wrong in this code? How can I correct it?</p>
  
  <p>Is there any other elegant method to filter outlier?</p>