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
Comment From: jreback
duplicates https://github.com/pandas-dev/pandas/issues/7895 and #12319