@@ -3968,26 +3968,44 @@ def nsmallest(
39683968 """
39693969 return selectn .SelectNSeries (self , n = n , keep = keep ).nsmallest ()
39703970
3971- @ doc (
3972- klass = _shared_doc_kwargs [ "klass" ],
3973- extra_params = dedent (
3974- """copy : bool, default True
3975- Whether to copy underlying data .
3971+ def swaplevel (
3972+ self , i : Level = - 2 , j : Level = - 1 , copy : bool | lib . NoDefault = lib . no_default
3973+ ) -> Series :
3974+ """
3975+ Swap levels i and j in a :class:`MultiIndex` .
39763976
3977- .. note::
3978- The `copy` keyword will change behavior in pandas 3.0.
3979- `Copy-on-Write
3980- <https://pandas.pydata.org/docs/dev/user_guide/copy_on_write.html>`__
3981- will be enabled by default, which means that all methods with a
3982- `copy` keyword will use a lazy copy mechanism to defer the copy and
3983- ignore the `copy` keyword. The `copy` keyword will be removed in a
3984- future version of pandas.
3977+ Default is to swap the two innermost levels of the index.
3978+
3979+ Parameters
3980+ ----------
3981+ i, j : int or str
3982+ Levels of the indices to be swapped. Can pass level name as string.
3983+ copy : bool, default True
3984+ Whether to copy underlying data.
3985+
3986+ .. note::
3987+ The `copy` keyword will change behavior in pandas 3.0.
3988+ `Copy-on-Write
3989+ <https://pandas.pydata.org/docs/dev/user_guide/copy_on_write.html>`__
3990+ will be enabled by default, which means that all methods with a
3991+ `copy` keyword will use a lazy copy mechanism to defer the copy
3992+ and ignore the `copy` keyword. The `copy` keyword will be
3993+ removed in a future version of pandas.
3994+
3995+ You can already get the future behavior and improvements through
3996+ enabling copy on write ``pd.options.mode.copy_on_write = True``
3997+
3998+ Returns
3999+ -------
4000+ Series
4001+ Series with levels swapped in MultiIndex.
4002+
4003+ See Also
4004+ --------
4005+ DataFrame.swaplevel : Swap levels i and j in a :class:`DataFrame`.
4006+ Series.reorder_levels : Rearrange index levels using input order.
4007+ MultiIndex.swaplevel : Swap levels i and j in a :class:`MultiIndex`.
39854008
3986- You can already get the future behavior and improvements through
3987- enabling copy on write ``pd.options.mode.copy_on_write = True``"""
3988- ),
3989- examples = dedent (
3990- """\
39914009 Examples
39924010 --------
39934011 >>> s = pd.Series(
@@ -4037,29 +4055,7 @@ def nsmallest(
40374055 Geography Final exam February B
40384056 History Coursework March A
40394057 Geography Coursework April C
4040- dtype: object"""
4041- ),
4042- )
4043- def swaplevel (
4044- self , i : Level = - 2 , j : Level = - 1 , copy : bool | lib .NoDefault = lib .no_default
4045- ) -> Series :
4046- """
4047- Swap levels i and j in a :class:`MultiIndex`.
4048-
4049- Default is to swap the two innermost levels of the index.
4050-
4051- Parameters
4052- ----------
4053- i, j : int or str
4054- Levels of the indices to be swapped. Can pass level name as string.
4055- {extra_params}
4056-
4057- Returns
4058- -------
4059- {klass}
4060- {klass} with levels swapped in MultiIndex.
4061-
4062- {examples}
4058+ dtype: object
40634059 """
40644060 self ._check_copy_deprecation (copy )
40654061 assert isinstance (self .index , MultiIndex )
0 commit comments