File tree 2 files changed +14
-12
lines changed
2 files changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -343,6 +343,20 @@ Index level names may be supplied as keys.
343
343
344
344
s.groupby([" first" , " second" ]).sum()
345
345
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
+
346
360
More on the ``sum `` function and aggregation later.
347
361
348
362
Grouping DataFrame with Index levels and columns
Original file line number Diff line number Diff line change @@ -8332,18 +8332,6 @@ def update(
8332
8332
1 Falcon 370.0
8333
8333
2 Parrot 24.0
8334
8334
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
8347
8335
"""
8348
8336
)
8349
8337
@Appender (_shared_docs ["groupby" ] % _shared_doc_kwargs )
You can’t perform that action at this time.
0 commit comments