title: Eliminate outliers in a dataframe with different dtypes - Pandas
body: <p>I want to eliminate the outliers in a dataframe that has columns with different dtypes (int64 and object). I need to remove all rows that have outliers in at least one column. So, I tried to use the following code:</p>
  <pre><code>from scipy import stats
  df[(np.abs(stats.zscore(df)) &lt; 3).all(axis=1)]
  </code></pre>
  <p>For each column, this code computes the Z-score for each value by using the column's mean and standard deviation. 'all(axis=1)' guarantees that for each row, all columns satisfy the constraint (absolute value of each z-score is below 3).</p>
  <p>However, as some columns' dtype is 'object', I am receiving the following error: <code>TypeError: unsupported operand type(s) for /: 'str' and 'int'</code></p>
  <p>I think this is happening because it is not possible to calculate the z-score in columns that only have strings ('object' dtype). So, I need a code that considers only the numerical columns to detect and eliminate the outliers.</p>
  <p>Do you know how to eliminate outliers in a dataframe that has columns with different dtypes (int64 and object)?</p>
  <p>This dataframe is about property rentals in Brazil. You can create a sample by using the following code:</p>
  <pre><code>data = {
      'city': ['São Paulo', 'Rio', 'Recife'],
      'area(m2)': [90, 120, 60],
      'Rooms': [3, 2, 4],
      'Bathrooms': [2, 3, 3],
      'animal': ['accept', 'do not accept', 'accept'],
      'rent($)': [2000, 3000, 800]
  }
  
  df = pd.DataFrame(
      data,
      columns=['city', 'area(m2)', 'Rooms', 'Bathrooms', 'animal', 'rent($)']
  )
  
  print(df)
  </code></pre>
  <p>This is how the sample looks:</p>
  <pre><code>       city  area(m2)  Rooms  Bathrooms         animal  rent($)
  0  São Paulo        90      3          2         accept     2000
  1        Rio       120      2          3  do not accept     3000
  2     Recife        60      4          3         accept      800
  </code></pre>
  <p>The original dataset can be found at: <a href="https://www.kaggle.com/rubenssjr/brasilian-houses-to-rent" rel="nofollow noreferrer">https://www.kaggle.com/rubenssjr/brasilian-houses-to-rent</a></p>