-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
DOC: Clarify groupby axis operations #62853
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
Merged
rhshadrach
merged 4 commits into
pandas-dev:main
from
justmhie:doc-groupby-axis-clarification
Nov 2, 2025
+2
−2
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7d0980c
DOC: Clarify groupby operates on axis 0 and remove 'selected axis' re…
justmhie 6bfdbde
DOC: Fix trailing whitespace in groupby.rst
justmhie 3635d81
DOC: Simplify groupby docs per reviewer feedback
justmhie 5f6b247
Merge remote-tracking branch 'upstream/main' into doc-groupby-axis-cl…
justmhie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,8 +137,9 @@ We could naturally group by either the ``A`` or ``B`` columns, or both: | |
|
|
||
| ``df.groupby('A')`` is just syntactic sugar for ``df.groupby(df['A'])``. | ||
|
|
||
| The above GroupBy will split the DataFrame on its index (rows). To split by columns, first do | ||
| a transpose: | ||
| The above GroupBy will split the DataFrame on its index (rows). DataFrame groupby | ||
| always operates along axis 0 (rows). To split by columns instead, first transpose | ||
| the DataFrame: | ||
|
|
||
| .. ipython:: | ||
|
|
||
|
|
@@ -151,6 +152,11 @@ a transpose: | |
|
|
||
| In [5]: grouped = df.T.groupby(get_letter_type) | ||
|
|
||
| .. note:: | ||
|
|
||
| Prior to pandas 3.0, groupby had an ``axis`` parameter. This has been removed. | ||
| To group by columns, transpose your DataFrame using ``.T`` before calling groupby. | ||
|
||
|
|
||
| pandas :class:`~pandas.Index` objects support duplicate values. If a | ||
| non-unique index is used as the group key in a groupby operation, all values | ||
| for the same index value will be considered to be in one group and thus the | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9432,7 +9432,7 @@ def groupby( | |
| index. If a dict or Series is passed, the Series or dict VALUES | ||
| will be used to determine the groups (the Series' values are first | ||
| aligned; see ``.align()`` method). If a list or ndarray of length | ||
| equal to the selected axis is passed (see the `groupby user guide | ||
| equal to the number of rows is passed (see the `groupby user guide | ||
|
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. Great catch! |
||
| <https://pandas.pydata.org/pandas-docs/stable/user_guide/groupby.html#splitting-an-object-into-groups>`_), | ||
| the values are used as-is to determine the groups. A label or list | ||
| of labels may be passed to group by the columns in ``self``. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I like the addition of "always" here, clarifying that it isn't just the example above. However these two sentences seem redundant:
and
Can you combine them.
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.
Also I don't see any significant difference between
and
This seems to me to just be a matter of personal style or taste. I generally think we should not make changes unless they are objectively positive.