|
76 | 76 | __all__ = ['Series']
|
77 | 77 |
|
78 | 78 | _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'}", |
80 | 80 | inplace="""inplace : boolean, default False
|
81 | 81 | If True, performs operation inplace and returns None.""",
|
82 | 82 | unique='np.ndarray', duplicated='Series',
|
@@ -2066,10 +2066,112 @@ def update(self, other):
|
2066 | 2066 | # ----------------------------------------------------------------------
|
2067 | 2067 | # Reindexing, sorting
|
2068 | 2068 |
|
2069 |
| - @Appender(generic._shared_docs['sort_values'] % _shared_doc_kwargs) |
2070 | 2069 | def sort_values(self, axis=0, ascending=True, inplace=False,
|
2071 | 2070 | 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. |
2072 | 2097 |
|
| 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 | + """ |
2073 | 2175 | inplace = validate_bool_kwarg(inplace, 'inplace')
|
2074 | 2176 | axis = self._get_axis_number(axis)
|
2075 | 2177 |
|
|
0 commit comments