- API reference
- Series
- pandas.Series.agg
pandas.Series.agg#
- Series.agg(func=None,axis=0,*args,**kwargs)[source]#
Aggregate using one or more operations over the specified axis.
- Parameters:
- funcfunction, str, list or dict
Function to use for aggregating the data. If a function, must eitherwork when passed a Series or when passed to Series.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.
- axis{0 or ‘index’}
Unused. Parameter needed for compatibility with DataFrame.
- *args
Positional arguments to pass tofunc.
- **kwargs
Keyword arguments to pass tofunc.
- 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
See also
Series.apply
Invoke function on a Series.
Series.transform
Transform function producing a Series with like indexes.
Notes
The aggregation operations are always performed over an axis, either theindex (default) or the column axis. This behavior is different fromnumpy aggregation functions (mean,median,prod,sum,std,var), where the default is to compute the aggregation of the flattenedarray, e.g.,
numpy.mean(arr_2d)
as opposed tonumpy.mean(arr_2d,axis=0)
.agg is an alias foraggregate. Use the alias.
Functions that mutate the passed object can produce unexpectedbehavior or errors and are not supported. SeeMutating with User Defined Function (UDF) methodsfor more details.
A passed user-defined-function will be passed a Series for evaluation.
Examples
>>>s=pd.Series([1,2,3,4])>>>s0 11 22 33 4dtype: int64
>>>s.agg('min')1
>>>s.agg(['min','max'])min 1max 4dtype: int64