Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
z3 = pd.DataFrame({"a":[10], "b":[2], "c": [1]}).set_index(["a", "b"])
maturities = list(range(100))
z4 = z3.reindex(maturities,level=1)
Issue Description
I create a 1 row dataframe with multiindex
I reindex on a single level, and I expect all values in the new index to be in the new dataframe.
instead, the same dataframe is returned.
the same happens with more than a single row.
If I use a 1d index, or apply to the columns, I get a 100 row/column dataframe as expected
Expected Behavior
expected_output = pd.DataFrame({"a":10, "b": range(100), "c": np.nan}).set_index(["a", "b"])
expected_output.loc[(10,2), "c"]=1
expected_output.head()
# c
# a b
# 10 0 NaN
# 1 NaN
# 2 1.0
# 3 NaN
# 4 NaN
Installed Versions
pandas : 2.1.1
numpy : 1.26.0
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.2.2
pip : 23.2.1
Cython : None
pytest : None
hypothesis : None
sphinx : 7.2.6
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.15.0
pandas_datareader : None
bs4 : None
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.0
numba : None
numexpr : None
odfpy
5BBF
: None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None