Skip to content

Commit

Permalink
DOC: update the MultiIndex.swaplevel docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
xrmx committed Mar 10, 2018
1 parent 52cffa3 commit f52fa36
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1775,22 +1775,44 @@ def droplevel(self, level=0):

def swaplevel(self, i=-2, j=-1):
"""
Swap level i with level j. Do not change the ordering of anything
Swap level i with level j.
Calling this method does not change the ordering of anything.
Parameters
----------
i, j : int, string (can be mixed)
Level of index to be swapped. Can pass level name as string.
i : int, str
First level of index to be swapped. Can pass level name as string.
Type of parameters can be mixed.
j : int, str
Second level of index to be swapped. Can pass level name as string.
Type of parameters can be mixed.
Returns
-------
swapped : MultiIndex
MultiIndex
A newly allocated MultiIndex
.. versionchanged:: 0.18.1
The indexes ``i`` and ``j`` are now optional, and default to
the two innermost levels of the index.
See Also
--------
MultiIndex : A multi-level, or hierarchical, index object for
pandas objects.
Examples
--------
>>> mi = pd.MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
... labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
>>> mi
MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
>>> mi.swaplevel()
MultiIndex(levels=[['bb', 'aa'], ['a', 'b']],
labels=[[0, 1, 0, 1], [0, 0, 1, 1]])
"""
new_levels = list(self.levels)
new_labels = list(self.labels)
Expand Down

0 comments on commit f52fa36

Please sign in to comment.