From 740d0b422a27d51dcb957694095f61511f2007f5 Mon Sep 17 00:00:00 2001 From: Raana Saheb Nassagh Date: Tue, 18 Apr 2023 13:51:32 +0000 Subject: [PATCH 1/5] fix issue 47529 --- pandas/core/shared_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index 8344430ca5bb9..423328138dac6 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -130,7 +130,7 @@ sort : bool, default True Sort group keys. Get better performance by turning this off. Note this does not influence the order of observations within each - group. Groupby preserves the order of rows within each group. + group. Groupby preserves the order of rows within each group. If False the order among groups with their keys follows the order of appearance of the keys in the original dataframe. This argument has no effect on filtrations (see the `filtrations in the user guide `_), such as ``head()``, ``tail()``, ``nth()`` and in transformations From 128574c163d332aa364db4815f8828774f887848 Mon Sep 17 00:00:00 2001 From: Raana Saheb Nassagh Date: Tue, 18 Apr 2023 14:06:53 +0000 Subject: [PATCH 2/5] add info for sort=false in groupby.rst --- doc/source/user_guide/groupby.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index f74012cf51d4a..9bf4e503b1831 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -196,7 +196,7 @@ only verifies that you've passed a valid mapping. GroupBy sorting ~~~~~~~~~~~~~~~~~~~~~~~~~ -By default the group keys are sorted during the ``groupby`` operation. You may however pass ``sort=False`` for potential speedups: +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: .. ipython:: python @@ -205,7 +205,7 @@ By default the group keys are sorted during the ``groupby`` operation. You may h df2.groupby(["X"], sort=False).sum() -Note that ``groupby`` will preserve the order in which *observations* are sorted *within* each group. +Note that ``groupby`` will preserve the order in which *observations* are sorted *within* each group . For example, the groups created by ``groupby()`` below are in the order they appeared in the original ``DataFrame``: .. ipython:: python From f936ea8635e87d563bc06afec16ebadb0be4737f Mon Sep 17 00:00:00 2001 From: Raana Saheb Nassagh Date: Tue, 18 Apr 2023 14:24:32 +0000 Subject: [PATCH 3/5] fixed pre-commit problem --- doc/source/user_guide/groupby.rst | 2 +- pandas/core/shared_docs.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index 9bf4e503b1831..e528d17c64d32 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -196,7 +196,7 @@ only verifies that you've passed a valid mapping. GroupBy sorting ~~~~~~~~~~~~~~~~~~~~~~~~~ -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: +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: .. ipython:: python diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index 423328138dac6..3dc5bc684330c 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -130,7 +130,9 @@ sort : bool, default True Sort group keys. Get better performance by turning this off. Note this does not influence the order of observations within each - group. Groupby preserves the order of rows within each group. If False the order among groups with their keys follows the order of appearance of the keys in the original dataframe. + group. Groupby preserves the order of rows within each group. If False + the order among groups with their keys follows the order of appearance + of the keys in the original dataframe. This argument has no effect on filtrations (see the `filtrations in the user guide `_), such as ``head()``, ``tail()``, ``nth()`` and in transformations From 5c45249913aadfc05b9eb3b502e0111ff4937da8 Mon Sep 17 00:00:00 2001 From: raanasn Date: Wed, 19 Apr 2023 14:46:14 +0200 Subject: [PATCH 4/5] Update pandas/core/shared_docs.py for groupby sort Co-authored-by: Marco Edward Gorelli <33491632+MarcoGorelli@users.noreply.github.com> --- pandas/core/shared_docs.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index 3dc5bc684330c..0e37ec5dc45f0 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -130,9 +130,8 @@ sort : bool, default True Sort group keys. Get better performance by turning this off. Note this does not influence the order of observations within each - group. Groupby preserves the order of rows within each group. If False - the order among groups with their keys follows the order of appearance - of the keys in the original dataframe. + group. Groupby preserves the order of rows within each group. If False, + the groups will appear in the same order as they did in the original DataFrame. This argument has no effect on filtrations (see the `filtrations in the user guide `_), such as ``head()``, ``tail()``, ``nth()`` and in transformations From 182dc2bc00e4caa488513e828d942e3bc6d18a81 Mon Sep 17 00:00:00 2001 From: Raana Saheb Nassagh Date: Thu, 20 Apr 2023 16:09:15 +0000 Subject: [PATCH 5/5] removed additional space in groupby.rst --- doc/source/user_guide/groupby.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index e528d17c64d32..88727bc8f9025 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -205,7 +205,7 @@ By default the group keys are sorted during the ``groupby`` operation. You may h df2.groupby(["X"], sort=False).sum() -Note that ``groupby`` will preserve the order in which *observations* are sorted *within* each group . +Note that ``groupby`` will preserve the order in which *observations* are sorted *within* each group. For example, the groups created by ``groupby()`` below are in the order they appeared in the original ``DataFrame``: .. ipython:: python