Reputation: 97
Hello a Python newbie here.
I have a dataframe that shows the product and how much they sold on each date
I need to change this dataframe to show the aggregate amount of units sold.
This is just an example dataframe and the actual dataframe that I am dealing with contains hundreds of products and 3 years worth of sales data.
It would be appreciated if there would be a way to do this efficiently.
Thank you in advance!!
Upvotes: 2
Views: 50
Reputation: 862661
If product
is column use DataFrame.set_index
with DataFrame.cumsum
for cumulative sum:
df1 = df.set_index('product').cumsum(axis=1)
If product is index
:
df1 = df.cumsum(axis=1)
Upvotes: 1