Skip to content

ENH: MultiIndex.dtypes #37062

Closed
Closed
@jreback

Description

@jreback

create a mi

In [13]: mi = pd.MultiIndex.from_product([[1,2,3], list('abc'), pd.date_range('20200101', periods=2, tz='UTC')], names=['int', 'string', 'dt'])                            

You can already get .dtypes, but is slightly cumbersome. I would propose adding Multidex.dtypes (we already have MultiIndex.dtype but its always object). I think this is worth the convenience api.

In [14]: mi.to_frame().dtypes                                                                                                                                              
Out[14]: 
int                     int64
string                 object
dt        datetime64[ns, UTC]
dtype: object

# we would actually implement like this.
In [15]: pd.Series({l.name: l.dtype for l in mi.levels})                                                                                                                   
Out[15]: 
int                     int64
string                 object
dt        datetime64[ns, UTC]
dtype: object

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions