pandas.DataFrame.aggregate¶
-
DataFrame.
aggregate
(func, axis=0, *args, **kwargs)[source]¶ Aggregate using callable, string, dict, or list of string/callables
New in version 0.20.0.
Parameters: func : callable, string, dictionary, or list of string/callables
Function to use for aggregating the data. If a function, must either work when passed a DataFrame or when passed to DataFrame.apply. For a DataFrame, can pass a dict, if the keys are DataFrame column names.
Accepted Combinations are:
- string function name
- function
- list of functions
- dict of column names -> functions (or list of functions)
Returns: aggregated : DataFrame
See also
pandas.DataFrame.apply
,pandas.DataFrame.transform
,pandas.DataFrame.groupby.aggregate
,pandas.DataFrame.resample.aggregate
,pandas.DataFrame.rolling.aggregate
Notes
Numpy functions mean/median/prod/sum/std/var are special cased so the default behavior is applying the function along axis=0 (e.g., np.mean(arr_2d, axis=0)) as opposed to mimicking the default Numpy behavior (e.g., np.mean(arr_2d)).
agg is an alias for aggregate. Use the alias.
Examples
>>> df = pd.DataFrame(np.random.randn(10, 3), columns=['A', 'B', 'C'], ... index=pd.date_range('1/1/2000', periods=10)) >>> df.iloc[3:7] = np.nan
Aggregate these functions across all columns
>>> df.agg(['sum', 'min']) A B C sum -0.182253 -0.614014 -2.909534 min -1.916563 -1.460076 -1.568297
Different aggregations per column
>>> df.agg({'A' : ['sum', 'min'], 'B' : ['min', 'max']}) A B max NaN 1.514318 min -1.916563 -1.460076 sum -0.182253 NaN