-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
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
series1 = pd.Series(data=[1,2], index=['A','B'])
series2 = pd.Series(data=[3,4], index=['A','B'])
df = pd.DataFrame({'s1': series1, 's2': series2})
index = pd.MultiIndex.from_product([['C'],['A','B']])
df.index = index
# df is
# | |s1|s2|
#C|A| 1| 3|
# |B| 2| 4|
df2 = pd.DataFrame({'s1': series1, 's2': series2}, index=index)
# df2 is
# | | s1| s2|
#C|A|NaN|NaN|
# |B|NaN|NaN|
Issue Description
Dataframe fills with NaN when the Dataframe init / constructor is passed a MultiIndex for the index
argument (as in df2
). Only workaround is to replace the index after the dataframe is initialized (as in df
).
Example: df
is fine above, but df2
is filled with NaN.
Expected Behavior
df2
and df
should be the same above.
Installed Versions
INSTALLED VERSIONS
commit : 0691c5c
python : 3.10.11.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22631
machine : AMD64
processor : AMD64 Family 25 Model 33 Stepping 0, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 2.2.3
numpy : 1.23.5
pytz : 2023.3
dateutil : 2.8.2
setuptools : 65.5.0
pip : 24.2
Cython : 0.29.34
pytest : 7.4.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 5.3.0
html5lib : 1.1
pymysql : None
psycopg2 : 2.9.9
jinja2 : 3.1.2
IPython : 8.12.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : 2023.2.0
fsspec : 2023.4.0
gcsfs : None
matplotlib : 3.7.1
numba : 0.56.4
numexpr : 2.8.4
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
sqlalchemy : 2.0.9
tables : 3.8.0
tabulate : 0.9.0
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None