Closed
Description
-
I have checked that this issue has not already been reported.
-
(optional) I have confirmed this bug exists on the master branch of pandas.
There was a recent PR to add MultiIndex.dtypes
#37073 but this only works when each level is named.
pandas/pandas/core/indexes/multi.py
Lines 703 to 710 in 03e1c89
If level
has no name then, level.name
would be None
.
Example where it fails:
idx_multitype = pd.MultiIndex.from_product(
[[1, 2, 3], ["a", "b", "c"], pd.date_range("20200101", periods=2, tz="UTC")],
)
{level.name: level.dtype for level in idx_multitype.levels}
# {None: datetime64[ns, UTC]}
When level is unamed i.e None
may be we can add level_0
, level_1
etc. this would be consistent with API too(reset_index
would add level_x
).