title: Why removing outliers with Z-Score still leaves out some values as outliers?
body: <p>I am new to Ml. I am removing outliers with z-scores with the code given below. The problem I am facing is that when I remove outliers, it still leaves some values as outliers. Can anyone explain why is this so? Isn't Z-score a reliable method to remove all the outliers from the data?</p>
  <p>I am calculating the z-score second time to know if there are any data points still left.</p>
  <pre><code>for feature in numerical_features:
  
     data = pd.DataFrame(housing[feature], columns=[feature])
     data = data.copy()
     z_scores = np.abs(stats.zscore(data[feature]))
  
     print(&quot;Before z score on &quot;, feature, &quot; ====&gt; &quot;, data[z_scores &gt; 3].shape)
     data[z_scores &gt; 3] = data[feature].median()
  
     z_scores = np.abs(stats.zscore(data[feature]))
     print(&quot;After z score on &quot;, feature, &quot; ===&gt; &quot;, data[z_scores &gt; 3].shape)
     housing[feature] = data[feature]
     print()
  </code></pre>
  <p>Before z-score is the first time I apply z-score and tells me how many values will be impact when I replace with median.
  After means, how many values are still left as outliers?
  <a href="https://i.stack.imgur.com/g6kn2.png" rel="nofollow noreferrer">https://i.stack.imgur.com/g6kn2.png</a></p>