Skip to content

Commit 53b122d

Browse files
committed
updated the docstring in accordance with GH40378
1 parent 25ddc0c commit 53b122d

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

doc/source/user_guide/groupby.rst

+14
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,20 @@ Index level names may be supplied as keys.
343343
344344
s.groupby(["first", "second"]).sum()
345345
346+
When using ``.groupby()`` on a multiple index dataframe, do not specify both
347+
``by`` and ``level``.
348+
The argument validation should be done in ``.groupby()``,
349+
using the name of the specific index.
350+
351+
.. ipyton:: python
352+
353+
df = pandas.DataFrame({"col1": ["a", "b", "c"]})
354+
df.index = pandas.MultiIndex.from_arrays([["a", "a", "b"],
355+
[1, 2, 1]],
356+
names=["x", "y"])
357+
df.groupby(["col1", "x"]) # Fine
358+
df.groupby("col1", level=0) # TypeError
359+
346360
More on the ``sum`` function and aggregation later.
347361

348362
Grouping DataFrame with Index levels and columns

pandas/core/frame.py

-12
Original file line numberDiff line numberDiff line change
@@ -8332,18 +8332,6 @@ def update(
83328332
1 Falcon 370.0
83338333
2 Parrot 24.0
83348334
3 Parrot 26.0
8335-
8336-
When using ``.groupby()`` on a multiple index dataframe, do not specify both
8337-
``by`` and ``level``.
8338-
The argument validation should be done in ``.groupby()``,
8339-
using the name of the specific index.
8340-
8341-
>>> df = pandas.DataFrame({"col1": ["a", "b", "c"]})
8342-
>>> df.index = pandas.MultiIndex.from_arrays([["a", "a", "b"],
8343-
... [1, 2, 1]],
8344-
... names=["x", "y"])
8345-
>>> df.groupby(["col1", "x"]) # Fine
8346-
>>> df.groupby("col1", level=0) # TypeError
83478335
"""
83488336
)
83498337
@Appender(_shared_docs["groupby"] % _shared_doc_kwargs)

0 commit comments

Comments
 (0)