Skip to content

Commit 224ba7d

Browse files
author
Jon M. Mease
committed
Documentation updates for GH 5677
1 parent ab31dd6 commit 224ba7d

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

doc/source/groupby.rst

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ The mapping can be specified many different ways:
9494
- For DataFrame objects, a string indicating a column to be used to group. Of
9595
course ``df.groupby('A')`` is just syntactic sugar for
9696
``df.groupby(df['A'])``, but it makes life simpler
97+
- For DataFrame objects, a string indicating an index level to be used to group.
98+
If a string matches both an index level name and a column name then the column
99+
takes precedence
97100
- A list of any of the above things
98101

99102
Collectively we refer to the grouping objects as the **keys**. For example,

doc/source/whatsnew/v0.20.0.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ New features
2929

3030
Other enhancements
3131
^^^^^^^^^^^^^^^^^^
32-
33-
32+
- Strings passed to ``DataFrame.groupby()`` as the ``by`` parameter may now reference either column names or index level names (:issue:`5677`)
3433

3534

3635
.. _whatsnew_0200.api_breaking:

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3926,7 +3926,7 @@ def groupby(self, by=None, axis=0, level=None, as_index=True, sort=True,
39263926
Parameters
39273927
----------
39283928
by : mapping function / list of functions, dict, Series, or tuple /
3929-
list of column names.
3929+
list of column names or index level names.
39303930
Called on each element of the object index to determine the groups.
39313931
If a dict or Series is passed, the Series or dict VALUES will be
39323932
used to determine the groups

0 commit comments

Comments
 (0)