How to compute the cumulative sum of a column with Pandas using Python
Land Your First Data Science Job
A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.
If you already worked with time-series data, let me tell you a bit more about the cumulative sum function.
The cumulative sum function is extremely helpful when you want to know what is the sum of a variable over time.
Let me give you an example with E-commerce sales data.
So far so good!
Now that we have the sales volume per month in USD. One could ask the question how much total sales volume have we done so far.
Using the DataFrame.cumsum() we can compute that metric over time.
In Python
Resulting such DataFrame:
And if we plot it,
Here you are! You now know how to compute the cumulative sum of a column with Pandas in Python.
More on DataFrames
If you want to know more about DataFrame and Pandas. Check out the other articles I wrote on the topic, just here :
Land Your First Data Science Job
A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.
Related Articles
Continue your learning journey with these related topics
Master Data Science in Days, Not Months 🚀
Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚