Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/source/user_guide/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,17 @@ 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the last line here is coming from #40378 (comment). I was stating that the pandas code should validate the arguments, I don't understand what this sentence means in the documentation.

Also, I think this should be specified in the API docs for Series/DataFrame.groupby too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for the comments. I have submitted a new pull request (#47825). Feel free to look at the code. Thanks!


.. 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
Expand Down