Pandas Series: aggregate() function
Aggregation with pandas series
The aggregate() function uses to one or more operations over the specified axis.
Syntax:
Series.aggregate(self, func, axis=0, *args, **kwargs)
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
func | Function to use for aggregating the data. If a function, must either work when passed a Series or when passed to Series.apply. Accepted combinations are:
|
unction, str, list or dict | Required |
axis | Parameter needed for compatibility with DataFrame. | {0 or ‘index’} | Required |
args | Positional arguments to pass to func. | Required | |
**kwds | Keyword arguments to pass to func. | Required |
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
Notes:agg is an alias for aggregate. Use the alias.
A passed user-defined-function will be passed a Series for evaluation.
Example:
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series([2, 4, 6, 8, 10, 12])
s
Output:
0 2 1 4 2 6 3 8 4 10 5 12 dtype: int64
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series([2, 4, 6, 8, 10, 12])
s.agg('min')
Output:
2
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series([2, 4, 6, 8, 10, 12])
s.agg('min')
s.agg(['min', 'max'])
Output:
min 2 max 12 dtype: int64
Previous: Aggregation in Pandas
Next: Call function on self producing a Series in Pandas
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/pandas/series/series-aggregate.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics