Python | Pandas MultiIndex.is_lexsorted()
Last Updated :
24 Dec, 2018
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 lexicographically sorted. Otherwise the function return False
indicating the labels are not lexicographically sorted.
Syntax: MultiIndex.is_lexsorted()
Parameters : None
Returns : boolean
Example #1: Use MultiIndex.is_lexsorted()
function to check if the MultiIndex labels are lexicographically sorted or not.
import pandas as pd
midx = pd.MultiIndex.from_arrays([[ 'Networking' , 'Cryptography' ,
'Anthropology' , 'Science' ],
[ 88 , 84 , 98 , 95 ]])
print (midx)
|
Output :
Now let’s check if the labels in the MultiIndex are lexicographically sorted or not.
Output :
As we can see in the output, the function has returned false indicating that the labels in the MultiIndex are not lexicographically sorted.
Example #2: Use MultiIndex.is_lexsorted()
function to check if the MultiIndex labels are lexicographically sorted or not.
import pandas as pd
midx = pd.MultiIndex.from_arrays([[ 'Anthropology' , 'Cryptography' ,
'Networking' , 'Science' ],
[ 88 , 84 , 98 , 95 ]])
print (midx)
|
Output :
Now let’s check if the labels in the MultiIndex are lexicographically sorted or not.
Output :
As we can see in the output, the function has returned true indicating that the labels in the MultiIndex are lexicographically sorted.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...