Python | Pandas MultiIndex.to_hierarchical() 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_hierarchical() function return a MultiIndex reshaped to conform to the shapes given by n_repeat and n_shuffle. It is useful to replicate and rearrange a MultiIndex for combination with another Index with n_repeat items. Syntax: MultiIndex.to_hierarchical(n_repeat, n_shuffle=1) Parameters : n_repeat : Number of times to repeat the labels on self n_shuffle : Controls the reordering of the labels. If the result is going to be an inner level in a MultiIndex, n_shuffle will need to be greater than one. The size of each label must divisible by n_shuffle Returns : MultiIndex Example #1: Use MultiIndex.to_hierarchical() function to repeat the labels in the MultiIndex. 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 repeat the labels of the MultiIndex 2 times. Python3 # repeat the labels in the MultiIndex 2 times. midx.to_hierarchical(n_repeat = 2) Output : As we can see in the output, the labels in the returned MultiIndex is repeated 2 times. Example #2: Use MultiIndex.to_hierarchical() function to repeat as well as reshuffle the labels in the MultiIndex. 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 repeat and reshuffle the labels of the MultiIndex 2 times. Python3 # resetting the labels the MultiIndex midx.to_hierarchical(n_repeat = 2, n_shuffle = 2) Output : As we can see in the output, the labels are repeated as well as reshuffled twice in the returned MultiIndex. Comment More infoAdvertise with us Next Article Python | Pandas MultiIndex.to_hierarchical() S Shubham__Ranjan Follow Improve Article Tags : Technical Scripter Python Python-pandas Python pandas-multiIndex Practice Tags : python Similar Reads Python | Pandas MultiIndex.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 MultiIndex.to_frame() function create a DataFrame with the levels of the MultiI 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_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.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 Like