Skip to content

Commit 423fffd

Browse files
DOC: Add explanation of sort=false for groupby (#52736)
Co-authored-by: Marco Edward Gorelli <[email protected]>
1 parent 6b92b1c commit 423fffd

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

doc/source/user_guide/groupby.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ only verifies that you've passed a valid mapping.
196196
GroupBy sorting
197197
~~~~~~~~~~~~~~~~~~~~~~~~~
198198

199-
By default the group keys are sorted during the ``groupby`` operation. You may however pass ``sort=False`` for potential speedups:
199+
By default the group keys are sorted during the ``groupby`` operation. You may however pass ``sort=False`` for potential speedups. With ``sort=False`` the order among group-keys follows the order of appearance of the keys in the original dataframe:
200200

201201
.. ipython:: python
202202

pandas/core/shared_docs.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@
130130
sort : bool, default True
131131
Sort group keys. Get better performance by turning this off.
132132
Note this does not influence the order of observations within each
133-
group. Groupby preserves the order of rows within each group.
133+
group. Groupby preserves the order of rows within each group. If False,
134+
the groups will appear in the same order as they did in the original DataFrame.
134135
This argument has no effect on filtrations (see the `filtrations in the user guide
135136
<https://pandas.pydata.org/docs/dev/user_guide/groupby.html#filtration>`_),
136137
such as ``head()``, ``tail()``, ``nth()`` and in transformations

0 commit comments

Comments
 (0)