title: KeyError when dropping rows from Pandas dataframe
body: <p>I'm trying to drop some rows from a Pandas dataframe because they'd be considered outliers in data. I'm getting a KeyError when trying to drop some rows using the method my professor taught me.</p>
  <pre><code>gdp_2019_outliers = np.where(df_gdp['2019'] &gt; 6)
  df_gdp.drop(gdp_2019_outliers[0], inplace=True)
  gdp_2019_outliers_neg = np.where(df_gdp['2019'] &lt; -3)
  df_gdp.drop(gdp_2019_outliers_neg[0], inplace=True) # stacktrace points here as the cause
  
  gdp_2020_outliers = np.where(df_gdp['2020'] &gt; 3)
  df_gdp.drop(gdp_2020_outliers[0], inplace=True)
  gdp_2020_outliers_neg = np.where(df_gdp['2020'] &lt; -15)
  df_gdp.drop(gdp_2020_outliers_neg[0], inplace=True)
  </code></pre>
  <p>So, I find the outliers using <code>np.where()</code>, then pass the list of rows to <code>drop()</code>. It seems like it's trying to drop rows that are no longer in the dataframe, though -- like the first two lines of code dropped rows that were somehow refound.</p>
  <p>Any ideas? Is there a better way to drop rows using a condition?</p>
  <p>Stacktrack:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Users\colto\Documents\Spring 2022\Data Sciences\Module 5\DataWrangling\data_wrangling_project.py&quot;, line 104, in &lt;module&gt;
      df_gdp.drop(gdp_2019_outliers_neg[0], inplace=True)
    File &quot;C:\Users\colto\Documents\Spring 2022\Data Sciences\Module 5\DataWrangling\venv\lib\site-packages\pandas\util\_decorators.py&quot;, line 311, in wrapper
      return func(*args, **kwargs)
    File &quot;C:\Users\colto\Documents\Spring 2022\Data Sciences\Module 5\DataWrangling\venv\lib\site-packages\pandas\core\frame.py&quot;, line 4956, in drop
      return super().drop(
    File &quot;C:\Users\colto\Documents\Spring 2022\Data Sciences\Module 5\DataWrangling\venv\lib\site-packages\pandas\core\generic.py&quot;, line 4279, in drop
  ###############################################################################################################
      obj = obj._drop_axis(labels, axis, level=level, errors=errors)
    File &quot;C:\Users\colto\Documents\Spring 2022\Data Sciences\Module 5\DataWrangling\venv\lib\site-packages\pandas\core\generic.py&quot;, line 4323, in _drop_axis
      new_axis = axis.drop(labels, errors=errors)
    File &quot;C:\Users\colto\Documents\Spring 2022\Data Sciences\Module 5\DataWrangling\venv\lib\site-packages\pandas\core\indexes\base.py&quot;, line 6644, in drop
      raise KeyError(f&quot;{list(labels[mask])} not found in axis&quot;)
  KeyError: '[152] not found in axis'
  
  </code></pre>
  <pre><code>gdp_columns = ['Country Name', '1980', '1990', '2000', '2010', '2018', '2019', '2020']
  df_gdp = pd.read_csv(gdp_file, usecols=gdp_columns)
  </code></pre>
  <p>Dataset: <a href="https://www.kaggle.com/zackerym/gdp-annual-growth-for-each-country-1960-2020" rel="nofollow noreferrer">https://www.kaggle.com/zackerym/gdp-annual-growth-for-each-country-1960-2020</a></p>