The cummax(), cummin(), cumsum(), and cumprod() functions compute the maximum, minimum, sum, and product on a cumulative basis, respectively. Let's understand this by applying the cummax() function on the sample DataFrame:
sales_df.cummax()
The following is the output:
The skipna parameter in these functions provides control over handling NAs. It is set to True by default, and NAs are excluded. Consider the following DataFrame with NAs to understand the function of this parameter:
sales_df_na
The following is the output:
The cumsum() method can be applied as shown here:
sales_df_na.cumsum()
The following is the output:
We can choose to not ignore NAs while doing a cumulative sum by setting skipna to False:
sales_df_na.cumsum(skipna=False)
The following is the output:
By default, the aggregation is performed across the row axis since the axis parameter is set to 0 by default. Using the axis parameter, cumulative aggregation can also be performed across columns:
sales_df.cumprod(axis = 1)
The following is the output: