From d04dd267d51fc1215ed028aad1cb17e3ad14e4aa Mon Sep 17 00:00:00 2001 From: Anthony Givans Date: Mon, 18 Jul 2022 10:01:48 -0400 Subject: [PATCH 1/4] updated the docstring in accordance with GH40378 --- doc/source/user_guide/groupby.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index 5d8ef7ce02097..d06d91abfa8eb 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -345,6 +345,16 @@ Index level names may be supplied as keys. More on the ``sum`` function and aggregation later. +When using ``.groupby()`` on a DatFrame with a MultiIndex, do not specify both ``by`` and ``level``. +The argument validation should be done in ``.groupby()``, using the name of the specific index. + +.. ipython:: python + df = pd.DataFrame({"col1": ["a", "b", "c"]}) + df.index = pd.MultiIndex.from_arrays([["a", "a", "b"], + [1, 2, 1]], + names=["x", "y"]) + df.groupby(["col1", "x"]) + Grouping DataFrame with Index levels and columns ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A DataFrame may be grouped by a combination of columns and index levels by From 2a0f69eb37b53d4d31a7cf224cb4cdc88276dbce Mon Sep 17 00:00:00 2001 From: Anthony Givans Date: Mon, 18 Jul 2022 10:04:23 -0400 Subject: [PATCH 2/4] updated the docstring in accordance with GH40378 --- doc/source/user_guide/groupby.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index d06d91abfa8eb..7ad9e938ec22b 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -355,6 +355,8 @@ The argument validation should be done in ``.groupby()``, using the name of the names=["x", "y"]) df.groupby(["col1", "x"]) + + Grouping DataFrame with Index levels and columns ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A DataFrame may be grouped by a combination of columns and index levels by From 31de7358531abcd5ac2e5287601e03a697d76f55 Mon Sep 17 00:00:00 2001 From: Anthony Givans Date: Mon, 18 Jul 2022 10:04:45 -0400 Subject: [PATCH 3/4] updated the docstring in accordance with GH40378 --- doc/source/user_guide/groupby.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index 7ad9e938ec22b..d06d91abfa8eb 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -355,8 +355,6 @@ The argument validation should be done in ``.groupby()``, using the name of the names=["x", "y"]) df.groupby(["col1", "x"]) - - Grouping DataFrame with Index levels and columns ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A DataFrame may be grouped by a combination of columns and index levels by From 02677bcf67d4fbf671ec3f8bc0850c01f02722d6 Mon Sep 17 00:00:00 2001 From: Anthony Givans Date: Mon, 18 Jul 2022 10:53:09 -0400 Subject: [PATCH 4/4] updated the docstring in accordance with GH40378 --- doc/source/user_guide/groupby.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index d06d91abfa8eb..34244a8edcbfa 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -349,6 +349,7 @@ When using ``.groupby()`` on a DatFrame with a MultiIndex, do not specify both The argument validation should be done in ``.groupby()``, using the name of the specific index. .. ipython:: python + df = pd.DataFrame({"col1": ["a", "b", "c"]}) df.index = pd.MultiIndex.from_arrays([["a", "a", "b"], [1, 2, 1]],