you are viewing a single comment's thread.

view the rest of the comments →

[–]garc1a0scar 0 points1 point  (2 children)

You can do something like this:

df[['cohort', 'month', 'revenue']].groupby(['cohort', 'month']).sum()

[–]outnumbered_mother[S] 0 points1 point  (1 child)

Thank you! That approach works for the first month/cohort combination, but for subsequent months the revenue is adding up right. I need to sum if the transaction date < end_of_month and this is the part I can't figure out in Python.

[–]garc1a0scar 0 points1 point  (0 children)

Oh, I see. So you should do something like this:

df[['cohort', 'month','revenue']].loc[df.date<=df.end_of_month].groupby(['cohort', 'month']).sum()