You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The MultiIndex.to_frame function is great for working with multi-indexes as a meta-dataframe. I find myself using this paradigm very often.
df = create_multiindex_df()
meta = df.columns.to_frame(index=False)
meta = filter_multiindex()
df.reindex(columns=convert_df_to_multiindex(df))
Having the convert_df_to_multiindex as a pd.MultiIndex method would be extremely complimentary to pd.MultiIndex.to_frame.
A simplified one-line implementation provided below, not including accounting for some corner case behaviors and discerning between series/frames vs Index/Multiindex.