We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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.
import pandas as pd a = pd.DataFrame([[1,2,3,4],[5,6,7,8]], index=[['a','a'], ['x', 'y']]) a.reindex(['x','z'], level=1) # 0 1 2 3 #a x 1 2 3 4
pandas doesn't work properly for multiindex reindexing. It drops the index that didn't appear in the original dataset directly.
we expect pandas will reindex the second level of the multiindex to ['x' , 'z']. But it drops 'z' directly.
pd.show_versions()
commit : None python : 3.7.6.final.0 python-bits : 64 OS : Linux OS-release : 4.15.0-109-generic machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8
pandas : 1.0.1 numpy : 1.18.1 pytz : 2019.3 dateutil : 2.8.1 pip : 20.1.1 setuptools : 45.2.0.post20200210 Cython : 0.29.15 pytest : 5.3.5 hypothesis : 5.5.4 sphinx : 2.4.0 blosc : None feather : None xlsxwriter : 1.2.7 lxml.etree : 4.5.0 html5lib : 1.0.1 pymysql : None psycopg2 : None jinja2 : 2.11.1 IPython : 7.12.0 pandas_datareader: None bs4 : 4.8.2 bottleneck : 1.3.2 fastparquet : None gcsfs : None lxml.etree : 4.5.0 matplotlib : 3.1.3 numexpr : 2.7.1 odfpy : None openpyxl : 3.0.3 pandas_gbq : None pyarrow : None pytables : None pytest : 5.3.5 pyxlsb : None
The text was updated successfully, but these errors were encountered:
Thanks @chloe-wang for the report. This is a duplicate of #25460 so closing. LMK if I'm missing something and I'll reopen.
This issue also occurs with the first level.
>>> a.reindex(["x", "z"], level=1) 0 1 2 3 a x 1 2 3 4 >>> >>> a.reindex(["a", "b"], level=0) 0 1 2 3 a x 1 2 3 4 y 5 6 7 8 >>> >>> idx = pd.MultiIndex.from_product([["a"], ["x", "z"]]) >>> idx MultiIndex([('a', 'x'), ('a', 'z')], ) >>> >>> a.reindex(idx) 0 1 2 3 a x 1.0 2.0 3.0 4.0 z NaN NaN NaN NaN >>>
does reindexing using an explicit MultIndex give the expected result?
Sorry, something went wrong.
No branches or pull requests
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
Problem description
pandas doesn't work properly for multiindex reindexing. It drops the index that didn't appear in the original dataset directly.
Expected Output
we expect pandas will reindex the second level of the multiindex to ['x' , 'z']. But it drops 'z' directly.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-109-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.1
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.1.1
setuptools : 45.2.0.post20200210
Cython : 0.29.15
pytest : 5.3.5
hypothesis : 5.5.4
sphinx : 2.4.0
blosc : None
feather : None
xlsxwriter : 1.2.7
lxml.etree : 4.5.0
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : 7.12.0
pandas_datareader: None
bs4 : 4.8.2
bottleneck : 1.3.2
fastparquet : None
gcsfs : None
lxml.etree : 4.5.0
matplotlib : 3.1.3
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.3.5
pyxlsb : None
The text was updated successfully, but these errors were encountered: