Closed
Description
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.
pd.MultiIndex.from_tuples(list(df.values), names=df.columns)