Skip to content

reindex() does not reindex a MultiIndex #20048

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

Closed
dniku opened this issue Mar 8, 2018 · 1 comment
Closed

reindex() does not reindex a MultiIndex #20048

dniku opened this issue Mar 8, 2018 · 1 comment
Labels
API Design Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex

Comments

@dniku
Copy link

dniku commented Mar 8, 2018

Code Sample, a copy-pastable example if possible

df = pd.DataFrame.from_dict({'A': {(42, 'foo', 4): 0, (42, 'foo', 9): 0},
 'B': {(42, 'foo', 4): 0, (42, 'foo', 9): 0},
 'C': {(42, 'foo', 4): 0, (42, 'foo', 9): 0},
 'D': {(42, 'foo', 4): 0, (42, 'foo', 9): 0},
 'E': {(42, 'foo', 4): 0, (42, 'foo', 9): 0},
 'F': {(42, 'foo', 4): 0, (42, 'foo', 9): 0},
 'G': {(42, 'foo', 4): 1, (42, 'foo', 9): 1}})

print(df.reindex(pd.RangeIndex(-1, 11), level=2, fill_value=0))

Output:

          A  B  C  D  E  F  G
42 foo 4  0  0  0  0  0  0  1
       9  0  0  0  0  0  0  1

Problem description

I would expect that the resulting dataframe have 12 rows, with indices (42, 'foo', i) for i from -1 to 10.

Apologies if I am just misunderstanding something. I haven't managed to find any information in the docs on the reason for the current behavior.

Output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Linux
OS-release: 4.14.24-1-MANJARO
machine: x86_64
processor: 
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 38.5.1
Cython: 0.27.3
numpy: 1.14.0
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2018.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves API Design Duplicate Report Duplicate issue or pull request MultiIndex labels Mar 8, 2018
@jreback jreback added this to the No action milestone Mar 8, 2018
@jreback
Copy link
Contributor

jreback commented Mar 8, 2018

duplicates #7895 and #12319

@jreback jreback closed this as completed Mar 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex
Projects
None yet
Development

No branches or pull requests

2 participants