Skip to content

Feature Request: pd.MultiIndex.from_frame(). Complement to pd.MultiIndex.to_frame(). #22420

Closed
@ms7463

Description

@ms7463

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions