Skip to content

Commit 3209b69

Browse files
authored
DOC: Add examples to the method MultiIndex.is_lexsorted() (#32312)
1 parent 63957e4 commit 3209b69

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pandas/core/indexes/multi.py

+24
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,30 @@ def is_lexsorted(self) -> bool:
16531653
Returns
16541654
-------
16551655
bool
1656+
1657+
Examples
1658+
--------
1659+
In the below examples, the first level of the MultiIndex is sorted because
1660+
a<b<c, so there is no need to look at the next level.
1661+
1662+
>>> pd.MultiIndex.from_arrays([['a', 'b', 'c'], ['d', 'e', 'f']]).is_lexsorted()
1663+
True
1664+
>>> pd.MultiIndex.from_arrays([['a', 'b', 'c'], ['d', 'f', 'e']]).is_lexsorted()
1665+
True
1666+
1667+
In case there is a tie, the lexicographical sorting looks
1668+
at the next level of the MultiIndex.
1669+
1670+
>>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'b', 'c']]).is_lexsorted()
1671+
True
1672+
>>> pd.MultiIndex.from_arrays([[0, 1, 1], ['a', 'c', 'b']]).is_lexsorted()
1673+
False
1674+
>>> pd.MultiIndex.from_arrays([['a', 'a', 'b', 'b'],
1675+
... ['aa', 'bb', 'aa', 'bb']]).is_lexsorted()
1676+
True
1677+
>>> pd.MultiIndex.from_arrays([['a', 'a', 'b', 'b'],
1678+
... ['bb', 'aa', 'aa', 'bb']]).is_lexsorted()
1679+
False
16561680
"""
16571681
return self.lexsort_depth == self.nlevels
16581682

0 commit comments

Comments
 (0)