bpd.DataFrame.groupby¶
-
DataFrame.
groupby
(by)[source]¶ Group DataFrame by values in columns specified in by.
A groupby operation involves some combination of splitting the object, applying a function, and combining the results. this can be used to group large amounts of data and compute operations on these groups.
Parameters: by (label, or list of labels) – Used to determine the groups for the groupby. Should be a label or list of labels that will group by the named columns in self
. Notice that a tuple is interpreted a (single) key.Returns: df_gb – groupby object that contains information about the groups. Return type: DataFrameGroupBy Raises: KeyError
– If by not found in columnsExamples
>>> df =bpd.DataFrame(animal=['Falcon', 'Falcon', 'Parrot', 'Parrot'], ... max_speed=[380, 370, 24, 26]) >>> df.groupby('animal').mean() max_speed animal Falcon 375.0 Parrot 25.0