Series.agg() is used to pass a function or list of functions to be applied to a series or even to each element of a series individually. In the case of a list of functions, multiple results are returned by the
agg () method.
Syntax: Series.agg (func, axis = 0) p>
func: Function, list of function or string of function name to be called on Series.
axis: 0 or `index` for row wise operation and 1 or `columns` for column wise operation.
Return Type: The return type depends on return type of function passed as parameter.
Example # 1:
This example passes a lambda function that simply adds 2 to each value in the series. Since the function will be applied to each series value, the return type is also series. A random row of 10 elements is generated by passing an array using a random Numpy method.
As shown in the output, f an function has been applied to each value, and 2 — to each value in the series.
Example # 2: Passing a list of functions
This example passes a list of some default Python functions and the
agg method () returns multiple results in multiple variables.
As shown in the output, several results were returned. Min, Max and Sorted Array were returned in different variables result1, result2, result3 respectively.