When using a for loop with a dictionary of dataframes, DataFrame.drop() raises an unexpected error, apparently unable to find the label, even when that label exists and is handled correctly in a single df.

A small, complete example of the issue

>>> for key in dfs2:
>>>    dfs2[key].drop('0',axis=0,inplace=True)
---------------------------------------------------
ValueError        Traceback (most recent call last)
<ipython-input-179-3b991fac4b08> in <module>()
      1 for key in dfs2:
----> 2     dfs2[key].drop('0',axis=0,inplace=True)

/Library/Python/2.7/site-packages/pandas/core/generic.pyc in drop(self, labels, axis, level, inplace, errors)
   1875                 new_axis = axis.drop(labels, level=level, errors=errors)
   1876             else:
-> 1877                 new_axis = axis.drop(labels, errors=errors)
   1878             dropped = self.reindex(**{axis_name: new_axis})
   1879             try:

/Library/Python/2.7/site-packages/pandas/indexes/base.pyc in drop(self, labels, errors)
   3049             if errors != 'ignore':
   3050                 raise ValueError('labels %s not contained in axis' %
-> 3051                                  labels[mask])
   3052             indexer = indexer[~mask]
   3053         return self.delete(indexer)

ValueError: labels ['0'] not contained in axis

Iterating through a dict with DataFrame.drop does behave as expected (viz. successfully drop the row) when using errors='ignore'. However, I expected iteration with drop to behave as drop does with a single dataframe from the same dict:

Expected Output

>>> dfs2[key]
   A  B  C  D
a  1  2  3  4
b  2  3  4  5
0  3  4  5  6
d  4  5  6  7
e  5  6  7  8
>>> dfs2[key].drop('0',axis=0,inplace=True)
>>> dfs2[key]
   A  B  C  D
a  1  2  3  4
b  2  3  4  5
d  4  5  6  7
e  5  6  7  8

If different behavior for .drop when iterating is intended, a note in the docs might be helpful.

Output of pd.show_versions()

## INSTALLED VERSIONS commit: None python: 2.7.10.final.0 python-bits: 64 OS: Darwin OS-release: 15.4.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 pandas: 0.18.1 nose: 1.3.7 pip: 8.1.2 setuptools: 1.1.6 Cython: None numpy: 1.8.0rc1 scipy: 0.13.0b1 statsmodels: None xarray: None IPython: 5.0.0 sphinx: None patsy: None dateutil: 1.5 pytz: 2013.7 blosc: None bottleneck: None tables: None numexpr: None matplotlib: 1.3.1 openpyxl: 2.3.5 xlrd: 1.0.0 xlwt: None xlsxwriter: 0.9.3 lxml: None bs4: None html5lib: None httplib2: None apiclient: None sqlalchemy: None pymysql: None psycopg2: None jinja2: 2.8 boto: 2.42.0 pandas_datareader: None

Comment From: TomAugspurger

Can you edit your post to include a copy-patsable example (so how to generate dfs2)?

Comment From: jorisvandenbossche

@katelaurel I am going to close this issue, but happy to reopen when you can provide a reproducible example.