Python | Pandas MultiIndex.swaplevel() 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.swaplevel() function is used to swap levels of the MultiIndex. It swap level i with level j. Calling this method does not change the ordering of the values. Syntax: MultiIndex.swaplevel(i=-2, j=-1) Parameters : i : First level of index to be swapped. Can pass level name as string. Type of parameters can be mixed. j : Second level of index to be swapped. Can pass level name as string. Type of parameters can be mixed. Returns : A new MultiIndex Example #1: Use MultiIndex.swaplevel() function to swap the 0th level with the 1st level of the MultiIndex. Python3 # importing pandas as pd import pandas as pd # Create the MultiIndex midx = pd.MultiIndex.from_arrays([['Networking', 'Cryptography', 'Anthropology', 'Science'], [88, 84, 98, 95]]) # Print the MultiIndex print(midx) Output : Now let's swap the 0th level with the 1st level of the MultiIndex. Python3 # swap the levels midx.swaplevel(0, 1) Output : As we can see in the output, the function has swapped the 0th level with the 1st level of the MultiIndex. Example #2: Use MultiIndex.swaplevel() function to swap the 0th level with the 1st level of the MultiIndex. Python3 # importing pandas as pd import pandas as pd # Create the MultiIndex midx = pd.MultiIndex.from_arrays([['Beagle', 'Sephard', 'Labrador', 'Retriever'], [8, 4, 11, 3], ['A1', 'B1', 'A2', 'C1']]) # Print the MultiIndex print(midx) Output : Now let's swap the 0th level with the 2nd level of the MultiIndex. Python3 # swap the levels midx.swaplevel(0, 2) Output : As we can see in the output, the function has swapped the 0th level with the 2nd level of the MultiIndex. Comment More infoAdvertise with us Next Article Python | Pandas MultiIndex.from_tuples() S Shubham__Ranjan Follow Improve Article Tags : Technical Scripter Python Python-pandas Python pandas-multiIndex Practice Tags : python Similar Reads 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.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.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_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 Index.values Pandas Index is an immutable ndarray implementing an ordered, sliceable set. It is the basic object which stores the axis labels for all pandas objects. Pandas Index.values attribute return an array representing the data in the given Index object. Syntax: Index.values Parameter : None Returns : an a 2 min read Like