Skip to content

Commit b2e472a

Browse files
rafaruijorisvandenbossche
authored andcommitted
DOC: update Series.sort_values docstring (#20247)
1 parent fb7eac3 commit b2e472a

File tree

1 file changed

+104
-2
lines changed

1 file changed

+104
-2
lines changed

pandas/core/series.py

+104-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
__all__ = ['Series']
7777

7878
_shared_doc_kwargs = dict(
79-
axes='index', klass='Series', axes_single_arg="{0, 'index'}",
79+
axes='index', klass='Series', axes_single_arg="{0 or 'index'}",
8080
inplace="""inplace : boolean, default False
8181
If True, performs operation inplace and returns None.""",
8282
unique='np.ndarray', duplicated='Series',
@@ -2066,10 +2066,112 @@ def update(self, other):
20662066
# ----------------------------------------------------------------------
20672067
# Reindexing, sorting
20682068

2069-
@Appender(generic._shared_docs['sort_values'] % _shared_doc_kwargs)
20702069
def sort_values(self, axis=0, ascending=True, inplace=False,
20712070
kind='quicksort', na_position='last'):
2071+
"""
2072+
Sort by the values.
2073+
2074+
Sort a Series in ascending or descending order by some
2075+
criterion.
2076+
2077+
Parameters
2078+
----------
2079+
axis : {0 or 'index'}, default 0
2080+
Axis to direct sorting. The value 'index' is accepted for
2081+
compatibility with DataFrame.sort_values.
2082+
ascending : bool, default True
2083+
If True, sort values in ascending order, otherwise descending.
2084+
inplace : bool, default False
2085+
If True, perform operation in-place.
2086+
kind : {'quicksort', 'mergesort' or 'heapsort'}, default 'quicksort'
2087+
Choice of sorting algorithm. See also :func:`numpy.sort` for more
2088+
information. 'mergesort' is the only stable algorithm.
2089+
na_position : {'first' or 'last'}, default 'last'
2090+
Argument 'first' puts NaNs at the beginning, 'last' puts NaNs at
2091+
the end.
2092+
2093+
Returns
2094+
-------
2095+
Series
2096+
Series ordered by values.
20722097
2098+
See Also
2099+
--------
2100+
Series.sort_index : Sort by the Series indices.
2101+
DataFrame.sort_values : Sort DataFrame by the values along either axis.
2102+
DataFrame.sort_index : Sort DataFrame by indices.
2103+
2104+
Examples
2105+
--------
2106+
>>> s = pd.Series([np.nan, 1, 3, 10, 5])
2107+
>>> s
2108+
0 NaN
2109+
1 1.0
2110+
2 3.0
2111+
3 10.0
2112+
4 5.0
2113+
dtype: float64
2114+
2115+
Sort values ascending order (default behaviour)
2116+
2117+
>>> s.sort_values(ascending=True)
2118+
1 1.0
2119+
2 3.0
2120+
4 5.0
2121+
3 10.0
2122+
0 NaN
2123+
dtype: float64
2124+
2125+
Sort values descending order
2126+
2127+
>>> s.sort_values(ascending=False)
2128+
3 10.0
2129+
4 5.0
2130+
2 3.0
2131+
1 1.0
2132+
0 NaN
2133+
dtype: float64
2134+
2135+
Sort values inplace
2136+
2137+
>>> s.sort_values(ascending=False, inplace=True)
2138+
>>> s
2139+
3 10.0
2140+
4 5.0
2141+
2 3.0
2142+
1 1.0
2143+
0 NaN
2144+
dtype: float64
2145+
2146+
Sort values putting NAs first
2147+
2148+
>>> s.sort_values(na_position='first')
2149+
0 NaN
2150+
1 1.0
2151+
2 3.0
2152+
4 5.0
2153+
3 10.0
2154+
dtype: float64
2155+
2156+
Sort a series of strings
2157+
2158+
>>> s = pd.Series(['z', 'b', 'd', 'a', 'c'])
2159+
>>> s
2160+
0 z
2161+
1 b
2162+
2 d
2163+
3 a
2164+
4 c
2165+
dtype: object
2166+
2167+
>>> s.sort_values()
2168+
3 a
2169+
1 b
2170+
4 c
2171+
2 d
2172+
0 z
2173+
dtype: object
2174+
"""
20732175
inplace = validate_bool_kwarg(inplace, 'inplace')
20742176
axis = self._get_axis_number(axis)
20752177

0 commit comments

Comments
 (0)