title: How to remove Outliers in Python?
body: <p>I want to remove outliers from my dataset "train" for which purpose I've decided to use z-score or IQR.</p>
  
  <p>I'm running Jupyter notebook on Microsoft Python Client for SQL Server.</p>
  
  <p>I've tried for z-score:</p>
  
  <pre><code>from scipy import stats
  train[(np.abs(stats.zscore(train)) &lt; 3).all(axis=1)]
  </code></pre>
  
  <p>for IQR:</p>
  
  <pre><code>Q1 = train.quantile(0.02)
  Q3 = train.quantile(0.98)
  IQR = Q3 - Q1
  train = train[~((train &lt; (Q1 - 1.5 * IQR)) |(train &gt; (Q3 + 1.5 * 
  IQR))).any(axis=1)]
  </code></pre>
  
  <p>...which returns...</p>
  
  <p>for z-score:</p>
  
  <blockquote>
    <p>TypeError: unsupported operand type(s) for /: 'str' and 'int'</p>
  </blockquote>
  
  <p>for IQR:</p>
  
  <blockquote>
    <p>TypeError: unorderable types: str() &lt; float()</p>
  </blockquote>
  
  <p>My train dataset looks like:</p>
  
  <pre><code># Number of each type of column
  print('Training data shape: ', train.shape)
  train.dtypes.value_counts()
  </code></pre>
  
  <blockquote>
    <p>Training data shape:  (300000, 111) int32      66 float64    30 object     15 dtype: int64</p>
  </blockquote>
  
  <p>Help would be appreciated.</p>