@@ -9347,7 +9347,7 @@ def update(
93479347 # ----------------------------------------------------------------------
93489348 # Data reshaping
93499349 @deprecate_nonkeyword_arguments (
9350- Pandas4Warning , allowed_args = ["self" , "by" , "level" ], name = "groupby"
9350+ Pandas4Warning , allowed_args = ["self" , "by" , "level" ], name = "groupby"
93519351 )
93529352 def groupby (
93539353 self ,
@@ -9396,8 +9396,10 @@ def groupby(
93969396 Sort group keys. Get better performance by turning this off.
93979397 Note this does not influence the order of observations within each
93989398 group. Groupby preserves the order of rows within each group. If False,
9399- the groups will appear in the same order as they did in the original DataFrame.
9400- This argument has no effect on filtrations (see the `filtrations in the user guide
9399+ the groups will appear in the same order as they did in the original
9400+ DataFrame.
9401+ This argument has no effect on filtrations (see the `filtrations
9402+ in the user guide
94019403 <https://pandas.pydata.org/docs/dev/user_guide/groupby.html#filtration>`_),
94029404 such as ``head()``, ``tail()``, ``nth()`` and in transformations
94039405 (see the `transformations in the user guide
@@ -9465,16 +9467,19 @@ def groupby(
94659467
94669468 Examples
94679469 --------
9468- >>> df = pd.DataFrame({'Animal': ['Falcon', 'Falcon',
9469- ... 'Parrot', 'Parrot'],
9470- ... 'Max Speed': [380., 370., 24., 26.]})
9470+ >>> df = pd.DataFrame(
9471+ ... {
9472+ ... "Animal": ["Falcon", "Falcon", "Parrot", "Parrot"],
9473+ ... "Max Speed": [380.0, 370.0, 24.0, 26.0],
9474+ ... }
9475+ ... )
94719476 >>> df
94729477 Animal Max Speed
94739478 0 Falcon 380.0
94749479 1 Falcon 370.0
94759480 2 Parrot 24.0
94769481 3 Parrot 26.0
9477- >>> df.groupby([' Animal' ]).mean()
9482+ >>> df.groupby([" Animal" ]).mean()
94789483 Max Speed
94799484 Animal
94809485 Falcon 375.0
@@ -9485,11 +9490,12 @@ def groupby(
94859490 We can groupby different levels of a hierarchical index
94869491 using the `level` parameter:
94879492
9488- >>> arrays = [['Falcon', 'Falcon', 'Parrot', 'Parrot'],
9489- ... ['Captive', 'Wild', 'Captive', 'Wild']]
9490- >>> index = pd.MultiIndex.from_arrays(arrays, names=('Animal', 'Type'))
9491- >>> df = pd.DataFrame({'Max Speed': [390., 350., 30., 20.]},
9492- ... index=index)
9493+ >>> arrays = [
9494+ ... ["Falcon", "Falcon", "Parrot", "Parrot"],
9495+ ... ["Captive", "Wild", "Captive", "Wild"],
9496+ ... ]
9497+ >>> index = pd.MultiIndex.from_arrays(arrays, names=("Animal", "Type"))
9498+ >>> df = pd.DataFrame({"Max Speed": [390.0, 350.0, 30.0, 20.0]}, index=index)
94939499 >>> df
94949500 Max Speed
94959501 Animal Type
@@ -9527,7 +9533,7 @@ def groupby(
95279533 2.0 2 5
95289534 NaN 1 4
95299535
9530- >>> arr = [["a", 12, 12], [None, 12.3, 33.], ["b", 12.3, 123], ["a", 1, 1]]
9536+ >>> arr = [["a", 12, 12], [None, 12.3, 33.0 ], ["b", 12.3, 123], ["a", 1, 1]]
95319537 >>> df = pd.DataFrame(arr, columns=["a", "b", "c"])
95329538
95339539 >>> df.groupby(by="a").sum()
@@ -9546,18 +9552,21 @@ def groupby(
95469552 When using ``.apply()``, use ``group_keys`` to include or exclude the
95479553 group keys. The ``group_keys`` argument defaults to ``True`` (include).
95489554
9549- >>> df = pd.DataFrame({'Animal': ['Falcon', 'Falcon',
9550- ... 'Parrot', 'Parrot'],
9551- ... 'Max Speed': [380., 370., 24., 26.]})
9552- >>> df.groupby("Animal", group_keys=True)[['Max Speed']].apply(lambda x: x)
9555+ >>> df = pd.DataFrame(
9556+ ... {
9557+ ... "Animal": ["Falcon", "Falcon", "Parrot", "Parrot"],
9558+ ... "Max Speed": [380.0, 370.0, 24.0, 26.0],
9559+ ... }
9560+ ... )
9561+ >>> df.groupby("Animal", group_keys=True)[["Max Speed"]].apply(lambda x: x)
95539562 Max Speed
95549563 Animal
95559564 Falcon 0 380.0
95569565 1 370.0
95579566 Parrot 2 24.0
95589567 3 26.0
95599568
9560- >>> df.groupby("Animal", group_keys=False)[[' Max Speed' ]].apply(lambda x: x)
9569+ >>> df.groupby("Animal", group_keys=False)[[" Max Speed" ]].apply(lambda x: x)
95619570 Max Speed
95629571 0 380.0
95639572 1 370.0
@@ -9580,8 +9589,6 @@ def groupby(
95809589 dropna = dropna ,
95819590 )
95829591
9583-
9584-
95859592 _shared_docs ["pivot" ] = """
95869593 Return reshaped DataFrame organized by given index / column values.
95879594
0 commit comments