Pandas DataFrame: aggregate() function
DataFrame - aggregate() function
The aggregate() function is used to aggregate using one or more operations over the specified axis.
Syntax:
DataFrame.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 DataFrame or when passed to DataFrame.apply.
|
function, str, list or dict | Required |
axis | If 0 or 'index': apply function to each column. If 1 or 'columns': apply function to each row. | {0 or 'index', 1 or 'columns'} Default Value: 0 |
Required |
*args | Positional arguments to pass to func. | Required | |
**kwargs | 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
The aggregation operations are always performed over an axis, either the index (default) or the column axis. This behavior is different from numpy aggregation functions (mean, median, prod, sum, std, var), where the default is to compute the aggregation of the flattened array, e.g., numpy.mean(arr_2d) as opposed to numpy.mean(arr_2d, axis=0).
agg is an alias for aggregate. Use the alias.
Example:
Download the above Notebook from here.
Previous: DataFrame - agg() function
Next: DataFrame - transform() function
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework