-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: update Series.sort_values docstring #20247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
04c8faa
206b7e6
388ed2b
027e1e5
4aea67c
fef8f4c
fb7c0c8
3c61e6e
973b741
3d19051
668ada1
8b09ee5
3af4e29
afc528d
1264a6b
9717c8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1890,21 +1890,24 @@ def sort_values(self, axis=0, ascending=True, inplace=False, | |
""" | ||
Sort by the Series values. | ||
|
||
Sort (or order) a Series into ascending or descending order by some criterion. | ||
Sort (or order) a Series in ascending or descending order by some | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just say Sort |
||
criterion. | ||
|
||
Parameters | ||
---------- | ||
axis : {0 or ‘index’}, default 0 | ||
Axis to direct sorting. | ||
Axis to direct sorting. The value `index` is accepted for | ||
compatibility with DataFrame.sort_values. | ||
ascending : bool, default True | ||
If `True` sort values into ascending order, otherwise descending. | ||
If `True` sort values in ascending order, otherwise descending. | ||
inplace : bool, default False | ||
If True, perform operation in-place. | ||
kind : {‘quicksort’, ‘mergesort’ or ‘heapsort’}, default ‘quicksort’ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems you are using here not the 'normal' single quote, but king of curved smart quote. Can you change this? (see the quotes in the type description of the na_position keyword, that are the good ones) |
||
Choice of sorting algorithm. See also ndarray.np.sort [1]_ for more information. `mergesort` is the only stable | ||
algorithm. | ||
Choice of sorting algorithm. See also :func:`np.sort` for more | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. np.sort -> numpy.sort |
||
information. `mergesort` is the only stable algorithm. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. identation is off by one space here |
||
na_position : {'first' or 'last'}, default 'last' | ||
Argument `first` puts NaNs at the beginning, `last` puts NaNs at the end. | ||
Argument `first` puts NaNs at the beginning, `last` puts NaNs at | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For first and last, can you use normal single quotes (not backticks) like in the line above? |
||
the end. | ||
|
||
Returns | ||
------- | ||
|
@@ -1917,76 +1920,76 @@ def sort_values(self, axis=0, ascending=True, inplace=False, | |
DataFrame.sort_index : Sort DataFrame by indices. | ||
DataFrame.sort_values : Sort by the values along either axis. | ||
|
||
References | ||
---------- | ||
.. [1] https://docs.scipy.org/doc/numpy/reference/generated/numpy.sort.html | ||
|
||
Examples | ||
-------- | ||
>>> s = pd.Series([np.nan, 1, 232, 323, 1, 2, 3, 45]) | ||
>>> s = pd.Series([np.nan, 1, 3, 5, 10]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe put the 5 and 10 out of order? |
||
>>> s | ||
0 NaN | ||
1 1.0 | ||
2 232.0 | ||
3 323.0 | ||
4 1.0 | ||
5 2.0 | ||
6 3.0 | ||
7 45.0 | ||
0 NaN | ||
1 1.0 | ||
2 3.0 | ||
3 5.0 | ||
4 10.0 | ||
dtype: float64 | ||
|
||
Sort values ascending order | ||
Sort values ascending order (default behaviour) | ||
|
||
>>> s.sort_values(ascending=True) | ||
1 1.0 | ||
4 1.0 | ||
5 2.0 | ||
6 3.0 | ||
7 45.0 | ||
2 232.0 | ||
3 323.0 | ||
0 NaN | ||
1 1.0 | ||
2 3.0 | ||
3 5.0 | ||
4 10.0 | ||
0 NaN | ||
dtype: float64 | ||
|
||
Sort values descending order | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quick grammar comment: Sort values in descending order |
||
|
||
>>> s.sort_values(ascending=False) | ||
3 323.0 | ||
2 232.0 | ||
7 45.0 | ||
6 3.0 | ||
5 2.0 | ||
4 1.0 | ||
1 1.0 | ||
0 NaN | ||
4 10.0 | ||
3 5.0 | ||
2 3.0 | ||
1 1.0 | ||
0 NaN | ||
dtype: float64 | ||
|
||
Sort values inplace | ||
|
||
>>> s.sort_values(ascending=False, inplace=True) | ||
>>> s | ||
3 323.0 | ||
2 232.0 | ||
7 45.0 | ||
6 3.0 | ||
5 2.0 | ||
4 1.0 | ||
1 1.0 | ||
0 NaN | ||
4 10.0 | ||
3 5.0 | ||
2 3.0 | ||
1 1.0 | ||
0 NaN | ||
dtype: float64 | ||
|
||
Sort values putting NAs first | ||
|
||
>>> s.sort_values(na_position='first') | ||
0 NaN | ||
4 1.0 | ||
1 1.0 | ||
5 2.0 | ||
6 3.0 | ||
7 45.0 | ||
2 232.0 | ||
3 323.0 | ||
0 NaN | ||
1 1.0 | ||
2 3.0 | ||
3 5.0 | ||
4 10.0 | ||
dtype: float64 | ||
|
||
Sort a series of strings | ||
|
||
>>> s = pd.Series(['z', 'b', 'd', 'a', 'c']) | ||
>>> s | ||
0 z | ||
1 b | ||
2 d | ||
3 a | ||
4 c | ||
dtype: object | ||
|
||
>>> s.sort_values() | ||
3 a | ||
1 b | ||
4 c | ||
2 d | ||
0 z | ||
dtype: object | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you find time, it would be nice to have an example that includes strings as well so that users see that sorting can apply to anything. |
||
inplace = validate_bool_kwarg(inplace, 'inplace') | ||
axis = self._get_axis_number(axis) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by the values.