-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: DataFrame.drop
fails when there is a multiIndex without any level provided
#36293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, thanks for your report. You have to specify a level, when dropping parts of a Multiindex or give a list of tuples (lenght of tuples must match number of levels in MultiIndex). We could improve the error reporting here. |
@MarcoGorelli @phofl Can I please work on this issue? Will changing the exception message fix this issue? |
@phofl I just did some digging and it looks like the issue is not just an error message, but rather the behavior when there is an index duplicate (notice
yields
Is this really the intended behavior? |
Interesting, thanks very much. Don‘t knoww what the intended behavior is then |
Looked into it again: We use https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Index.isin.html when the index is not unique. Isin can not handle strings as input, because it creates a MultiIndex from the given inputs. When the index is unique, we use drop, which can handle strings as input. Part starts here: Line 4115 in 2067d7e
Is this behavior intended or should we search for a solution which is consisten between non unique and unique MultiIndexes? |
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.
Code Sample, a copy-pastable example
Problem description
I'd expected
drop
to drop all the rows withcow
as an index.Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 2a7d332
python : 3.7.3.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Thu Jun 18 20:49:00 PDT 2020; root:xnu-6153.141.1~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_US.UTF-8
pandas : 1.1.2
numpy : 1.17.3
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.1.0
Cython : None
pytest : None
hypothesis : 5.29.0
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: