To ensure you can follow us, we are using pandas
2.2.0, which is the latest version available at the time of writing this article.
You are probably already familiar with performing aggregations in pandas
using methods like sum
either min
. You have probably also used these methods in combination with groupby
. Therefore, it will not be a surprise that the agg
The method is used to perform one or more aggregations on a DataFrame. The interesting thing is that we can use agg
in several ways, depending on the syntax we use. Let's illustrate this with some examples.
Passing a dictionary to agg
method, we indicate which aggregations (sum, mean, maximum, etc.) we want to calculate for each column of the DataFrame. The keys of the dictionary represent the columns on which we want to perform aggregations, while the values represent the operations we want to execute.