Python | Pandas MultiIndex.to_frame() Last Updated : 24 Dec, 2018 Comments Improve Suggest changes Like Article Like Report Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas MultiIndex.to_frame() function create a DataFrame with the levels of the MultiIndex as columns. Syntax: MultiIndex.to_frame(index=True) Parameters : index : Set the index of the returned DataFrame as the original MultiIndex. Returns : DataFrame : a DataFrame containing the original MultiIndex data. Example #1: Use MultiIndex.to_frame() function to construct a dataframe using the MultiIndex levels as the column and index. Python3 # importing pandas as pd import pandas as pd # Create the MultiIndex midx = pd.MultiIndex.from_tuples([(10, 'Ten'), (10, 'Twenty'), (20, 'Ten'), (20, 'Twenty')], names =['Num', 'Char']) # Print the MultiIndex print(midx) Output : Now let's construct the dataframe from the MultiIndex. Python3 # Construct the DataFrame midx.to_frame(index = True) Output : As we can see in the output, the function has constructed the Dataframe using the MultiIndex. Notice the index of the dataframe is constructed using the levels of the MultiIndex. Example #2: Use MultiIndex.to_frame() function to construct a DataFrame using the MultiIndex. Do not use the MultiIndex levels to construct the index of the Dataframe. Python3 # importing pandas as pd import pandas as pd # Create the MultiIndex midx = pd.MultiIndex.from_tuples([(10, 'Ten'), (10, 'Twenty'), (20, 'Ten'), (20, 'Twenty')], names =['Num', 'Char']) # Print the MultiIndex print(midx) Output : Now let's create a dataframe using the midx MultiIndex. Python3 # Create Dataframe with new index values. midx.to_frame(index = False) Output : As we can see in the output, the function has returned a DataFrame having different index value. Comment More infoAdvertise with us Next Article Python | Pandas MultiIndex.to_frame() S Shubham__Ranjan Follow Improve Article Tags : Technical Scripter Python Python-pandas Python pandas-multiIndex Practice Tags : python Similar Reads Python | Pandas Index.to_frame() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.to_frame() function create a dataFrame from the given index with a column 2 min read Python | Pandas MultiIndex.from_tuples() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas MultiIndex.from_tuples() function is used to convert list of tuples to MultiInd 2 min read Python | Pandas MultiIndex.set_labels() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.Pandas MultiIndex.set_labels() function set new labels on MultiIndex. Defaults to retur 2 min read Python | Pandas MultiIndex.levshape Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas MultiIndex.levshape attribute outputs a tuple containing the length of each lev 2 min read Python | Pandas MultiIndex.from_arrays() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas MultiIndex.from_arrays() function is used to convert arrays into MultiIndex. It 2 min read Python | Pandas MultiIndex.droplevel() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas MultiIndex.droplevel() function return Index with requested level removed. If M 2 min read Python | Pandas MultiIndex.from_product() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas MultiIndex.from_product() function make a MultiIndex from the cartesian product 2 min read Python | Pandas MultiIndex.reorder_levels() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas MultiIndex.reorder_levels() function is used to rearrange levels using input or 2 min read Python | Pandas MultiIndex.sortlevel() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas MultiIndex.sortlevel() function sort MultiIndex at the requested level. The res 2 min read Python | Pandas MultiIndex.is_lexsorted() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas MultiIndex.is_lexsorted() function return True if the labels are lexicographica 2 min read Like