3 Upvotes

Creating a Running Total Column in Pandas

Python
Data Preprocessing

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

orders.sort_values(by=['Order_Date'], inplace=True)
orders['running_total'] = orders.groupby(['ProductID'],as_index=False) ['units'].cumsum()

By analyseup - Last Updated Jan. 12, 2022, 12:24 a.m.

Did you find this snippet useful?

Sign up to bookmark this in your snippet library

COMMENTS
RELATED SNIPPETS
Pivoting Pandas Dataframes
Python
Data Preprocessing

Pandas

3
2
Top Contributors
103
100