Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
import pandas as pd
lev_0 = [1, 2]
lev_1 = [1, 1]
idx = pd.MultiIndex.from_product([lev_0, lev_1])
df = pd.DataFrame(data={'a': range(0, len(idx))}, index=idx)
# Can't drop the first row use the code below, return the df itself.
df.drop(index=df.index[0])
# Also can’t drop the rows when passing a list-like index.
df.drop(index=df.index[0:1])
# When dropping by a single level, it works properly.
df.drop(index=1, level=0)
Problem description
When the DataFrame is MultiIndexed, and there's duplicated value in any level, DataFrame.drop() can't drop a row by an index tuple. I've tried swapping the levels' order, and there's still the same problem.
Expected Output
Drop the correct row by index.
Output of pd.show_versions()
[paste the output of pd.show_versions()
here leaving a blank line after the details tag]
INSTALLED VERSIONS
commit : c7f7443
python : 3.9.5.final.0
python-bits : 64
OS : Darwin
OS-release : 20.6.0
Version : Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 1.3.1
numpy : 1.20.1
pytz : 2021.1
dateutil : 2.8.1
pip : 21.2.1
setuptools : 56.0.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.4.3
lxml.etree : 4.6.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.21.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.13
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None