Skip to content

Commit 753d0ed

Browse files
authored
Specify that both by and level should not be specified in groupby - GH40378 (#47825)
Added that ``level`` and ``by`` should not be specified when using the ``groupby`` function (#40378)
1 parent 9e8387c commit 753d0ed

File tree

2 files changed

+1
-12
lines changed

2 files changed

+1
-12
lines changed

doc/source/user_guide/groupby.rst

-11
Original file line numberDiff line numberDiff line change
@@ -345,17 +345,6 @@ Index level names may be supplied as keys.
345345
346346
More on the ``sum`` function and aggregation later.
347347

348-
When using ``.groupby()`` on a DatFrame with a MultiIndex, do not specify both ``by`` and ``level``.
349-
The argument validation should be done in ``.groupby()``, using the name of the specific index.
350-
351-
.. ipython:: python
352-
353-
df = pd.DataFrame({"col1": ["a", "b", "c"]})
354-
df.index = pd.MultiIndex.from_arrays([["a", "a", "b"],
355-
[1, 2, 1]],
356-
names=["x", "y"])
357-
df.groupby(["col1", "x"])
358-
359348
Grouping DataFrame with Index levels and columns
360349
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
361350
A DataFrame may be grouped by a combination of columns and index levels by

pandas/core/shared_docs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
is unused and defaults to 0.
111111
level : int, level name, or sequence of such, default None
112112
If the axis is a MultiIndex (hierarchical), group by a particular
113-
level or levels.
113+
level or levels. Do not specify both ``by`` and ``level``.
114114
as_index : bool, default True
115115
For aggregated output, return object with group labels as the
116116
index. Only relevant for DataFrame input. as_index=False is

0 commit comments

Comments
 (0)