Cumulative Operations

Learm how to run cumulative operations on numerical values in pandas.

Overview

Cumulative operations are mathematical operations that involve the accumulation of intermediate results to produce the final result. Examples of cumulative operations include summing a series of numbers, calculating a product of a sequence of numbers, and finding the running total of a list of values. These operations can be useful in numerous situations, such as gaining insights into the data distribution and applying the Pareto principle (aka 80/20 rule) to identify patterns and prioritize action.

The pandas methods that allow us to perform cumulative operations are cumsum(), cumprod(), cummax() and cummin().

Sum and product

Before exploring cumulative operations, it’s helpful first to understand the methods of sum() and prod(). The sum() method returns the sum of values over an axis, while the prod() method returns the product of values over an axis. For example, we can find the row-wise sum and product of the Cards column of the credit card dataset with the following code:

Get hands-on with 1400+ tech skills courses.