From 224ba7d6fcbe9ddb18b1f2c0443d27c9909ac08f Mon Sep 17 00:00:00 2001 From: "Jon M. Mease" Date: Wed, 12 Oct 2016 21:03:00 -0400 Subject: [PATCH] Documentation updates for GH 5677 --- doc/source/groupby.rst | 3 +++ doc/source/whatsnew/v0.20.0.txt | 3 +-- pandas/core/generic.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/source/groupby.rst b/doc/source/groupby.rst index c5a77770085d6..0813a6527bb95 100644 --- a/doc/source/groupby.rst +++ b/doc/source/groupby.rst @@ -94,6 +94,9 @@ The mapping can be specified many different ways: - For DataFrame objects, a string indicating a column to be used to group. Of course ``df.groupby('A')`` is just syntactic sugar for ``df.groupby(df['A'])``, but it makes life simpler + - For DataFrame objects, a string indicating an index level to be used to group. + If a string matches both an index level name and a column name then the column + takes precedence - A list of any of the above things Collectively we refer to the grouping objects as the **keys**. For example, diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index 7fa9991138fba..cf3228fb58726 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -29,8 +29,7 @@ New features Other enhancements ^^^^^^^^^^^^^^^^^^ - - +- Strings passed to ``DataFrame.groupby()`` as the ``by`` parameter may now reference either column names or index level names (:issue:`5677`) .. _whatsnew_0200.api_breaking: diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 697438df87d4f..9866b54dd0542 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3926,7 +3926,7 @@ def groupby(self, by=None, axis=0, level=None, as_index=True, sort=True, Parameters ---------- by : mapping function / list of functions, dict, Series, or tuple / - list of column names. + list of column names or index level names. Called on each element of the object index to determine the groups. If a dict or Series is passed, the Series or dict VALUES will be used to determine the groups