Skip to content

Commit 833ef31

Browse files
authored
Specify that both by and level should not be specified in groupby - GH40378 (#47778)
* updated the docstring in accordance with GH40378 * updated the docstring in accordance with GH40378 * updated the docstring in accordance with GH40378 * updated the docstring in accordance with GH40378
1 parent 56bfb41 commit 833ef31

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

doc/source/user_guide/groupby.rst

+11
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,17 @@ 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+
348359
Grouping DataFrame with Index levels and columns
349360
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
350361
A DataFrame may be grouped by a combination of columns and index levels by

0 commit comments

Comments
 (0)