-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Passing level
to reindex
on a multi-index doesn't reindex the desired level
#25460
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
cc @toobaz |
Present in 0.23.4 It works for an Index (new row created) pd.DataFrame(dict(a=[1,2],b=[2,3]), index=[1,2]).reindex([1,2,3]) But not for a MultiIndex (new row is not created) a = pd.DataFrame(dict(a=[1,2],b=[2,3]), index=[[1,2],[3,4]])
a.index.names = ['a','b']
a.reindex([1,2,3], level='a') This affects joins too. Right joins of a MultiIndex to an Index will have the same effect as an inner join. Could be related. |
@simonjayhawkins Has this issue been resolved? I'm just encountering it in pandas 1.4.2. |
it's an open issue - you or anyone in the community can submit a patch |
I'm spent a few hours looking into the issue, but I am not familiar enough with index joins to know what the problem is. I think it might be happening in the function Within the function Finally near the end of the function Hope that helps someone willing to fix it. |
Thanks @ybagdasa for the investigation. Given this issue is a duplicate of #21147, which was itself a duplicate and closed. so closing this as duplicate of #12319 for the same reasons #21147 (comment) to help keep all the discussion in one place. (as there is also overlap with #7895) feel free to add your comments to those issues. |
Code Sample
Problem description
Passing
level
toreindex
on a multi-index doesn't reindex the desired level.Expected Output
In the above example, I'd expect to see two new rows, each containing
NaN
. The expected output is analogous to callingreindex
on a single-level index.I originally posted this issue as a question to StackOverflow, where a user kindly posted a workaround: https://stackoverflow.com/questions/54904974/extending-a-datetime-index-within-a-multi-index.
Output of
pd.show_versions()
pandas: 0.24.1
pytest: None
pip: 19.0.3
setuptools: 40.4.3
Cython: None
numpy: 1.15.3
scipy: 1.2.0
pyarrow: 0.12.1
xarray: None
IPython: 7.3.0
sphinx: None
patsy: None
dateutil: 2.7.3
pytz: 2018.6
blosc: None
bottleneck: 1.2.1
tables: None
numexpr: 2.6.8
feather: None
matplotlib: 3.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: 4.2.5
bs4: 4.7.1
html5lib: None
sqlalchemy: 1.2.12
pymysql: 0.9.2
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: 0.7.0
gcsfs: None
The text was updated successfully, but these errors were encountered: