Python | Pandas MultiIndex.nlevels 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.nlevels attribute returns the integer number of levels in the MultiIndex. Syntax: MultiIndex.nlevels Example #1: Use MultiIndex.nlevels attribute to find the number of levels in the MultiIndex. Python3 # importing pandas as pd import pandas as pd # Creating the array array = [[1, 2, 3], ['Sharon', 'Nick', 'Bailey']] # Print the array print(array) Output : Now let's create the MultiIndex using this array Python3 # Creating the MultiIndex midx = pd.MultiIndex.from_arrays(array, names =('Number', 'Names')) # Print the MultiIndex print(midx) Output : Now we will find the number of levels in the MultiIndex. Python3 1== # Print the number of the levels in MultiIndex midx.nlevels Output : As we can see in the output, there are 2 levels in the midx MultiIndex. Example #2: Use MultiIndex.nlevels attribute to find the number of levels in the given MultiIndex. Python3 # importing pandas as pd import pandas as pd # Creating the array array = [[1, 2, 3], ['Sharon', 'Nick', 'Bailey'], ['Doctor', 'Scientist', 'Physicist']] # Print the array print(array) Output : Now let's create the MultiIndex using this array Python3 # Creating the MultiIndex midx = pd.MultiIndex.from_arrays(array, names =('Ranking', 'Names', 'Profession')) # Print the MultiIndex print(midx) Output : Now we will find the number of levels in the MultiIndex. Python3 1== # Print the number of level in MultiIndex midx.nlevels Output : As we can see in the output, midx MultiIndex has 3 levels. Comment More infoAdvertise with us Next Article Python | Pandas Index.set_names() S Shubham__Ranjan Follow Improve Article Tags : Technical Scripter Python Python-pandas Python pandas-multiIndex Practice Tags : python Similar Reads Python | Pandas MultiIndex.names 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.names attribute returns the names of levels in the MultiIndex. Synta 2 min read Python | Pandas Index.isin() 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.isin() function return a boolean array where the index values are in valu 2 min read Python | Pandas Index.set_names() 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.set_names() function set new names on index. For the given Index it reset 2 min read Python | Pandas Index.get_loc() 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.get_loc() function return integer location, slice or boolean mask for req 3 min read Python | Pandas Index.nunique() 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.nunique() function return number of unique elements in the object. It ret 2 min read Python | Pandas Index.ndim 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.ndim attribute return the number of dimensions of the underlying data in the given Index object. By definition it is 1. Syntax: Index. 2 min read Like