pandas.core.window.rolling.Rolling.aggregate
函数定义
Rolling.aggregate(func, *args, **kwargs)
Aggregate using one or more operations over the specified axis.
函数参数
-
func:function, str, list or dict
Function to use for aggregating the data. If a function, must either work when passed a Series/Dataframe or when passed to Series/Dataframe.apply.
Accepted combinations are:- function
- string function name
- list of functions and/or function names, e.g.
[np.sum, 'mean']
- dict of axis labels -> functions, function names or list of such.
-
*args
Positional arguments to pass to func. -
**kwargs
Keyword arguments to pass to func.
函数返回值
Returns:scalar, Series or DataFrame
The return can be:
-
scalar : when Series.agg is called with single function
-
Series : when DataFrame.agg is called with a single function
-
DataFrame : when DataFrame.agg is called with several functions
注:agg is an alias for aggregate. Use the alias.
例子
df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]}) df A B C 0 1 4 7 1 2 5 8 2 3 6 9
df.rolling(2).sum() A B C 0 NaN NaN NaN 1 3.0 9.0 15.0 2 5.0 11.0 17.0
df.rolling(2).agg({"A": "sum", "B": "min"}) A B 0 NaN NaN 1 3.0 4.0 2 5.0 5.0