Skip to content

Specify that both by and level should not be specified in groupby - GH40378 #47825

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
merged 1 commit into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
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: 0 additions & 11 deletions doc/source/user_guide/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,6 @@ 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
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/shared_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
is unused and defaults to 0.
level : int, level name, or sequence of such, default None
If the axis is a MultiIndex (hierarchical), group by a particular
level or levels.
level or levels. Do not specify both ``by`` and ``level``.
as_index : bool, default True
For aggregated output, return object with group labels as the
index. Only relevant for DataFrame input. as_index=False is
Expand Down