Creating a Running Total Column in Pandas

Python

Creates a column in the orders DataFrame that contains a running total for each ProductID over time.

 1|  orders.sort_values(by=['Order_Date'], inplace=True)
 2|  orders['running_total'] = orders.groupby(['ProductID'],as_index=False)['units'].cumsum()
Did you find this snippet useful?

Sign up for free to to add this to your code library