Skip to content

Commit f52fa36

Browse files
committed
DOC: update the MultiIndex.swaplevel docstring
1 parent 52cffa3 commit f52fa36

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

pandas/core/indexes/multi.py

+26-4
Original file line numberDiff line numberDiff line change
@@ -1775,22 +1775,44 @@ def droplevel(self, level=0):
17751775

17761776
def swaplevel(self, i=-2, j=-1):
17771777
"""
1778-
Swap level i with level j. Do not change the ordering of anything
1778+
Swap level i with level j.
1779+
1780+
Calling this method does not change the ordering of anything.
17791781
17801782
Parameters
17811783
----------
1782-
i, j : int, string (can be mixed)
1783-
Level of index to be swapped. Can pass level name as string.
1784+
i : int, str
1785+
First level of index to be swapped. Can pass level name as string.
1786+
Type of parameters can be mixed.
1787+
j : int, str
1788+
Second level of index to be swapped. Can pass level name as string.
1789+
Type of parameters can be mixed.
17841790
17851791
Returns
17861792
-------
1787-
swapped : MultiIndex
1793+
MultiIndex
1794+
A newly allocated MultiIndex
17881795
17891796
.. versionchanged:: 0.18.1
17901797
17911798
The indexes ``i`` and ``j`` are now optional, and default to
17921799
the two innermost levels of the index.
17931800
1801+
See Also
1802+
--------
1803+
MultiIndex : A multi-level, or hierarchical, index object for
1804+
pandas objects.
1805+
1806+
Examples
1807+
--------
1808+
>>> mi = pd.MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
1809+
... labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
1810+
>>> mi
1811+
MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
1812+
labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
1813+
>>> mi.swaplevel()
1814+
MultiIndex(levels=[['bb', 'aa'], ['a', 'b']],
1815+
labels=[[0, 1, 0, 1], [0, 0, 1, 1]])
17941816
"""
17951817
new_levels = list(self.levels)
17961818
new_labels = list(self.labels)

0 commit comments

Comments
 (0)