ENH: MultiIndex.dtypes · Issue #37062 · pandas-dev/pandas (original) (raw)
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