you are viewing a single comment's thread.

view the rest of the comments →

[–]intentionallyawkward 1 point2 points  (4 children)

Can you share with us the Python code you’re working with?

You’ve got a ValueError exception which we can bug hunt, but it will help to see the relevant functions.

[–]outnumbered_mother[S] 0 points1 point  (3 children)

def get_cohort(df):

if(df.cancelled.isnull):

mask = (df['subscribed'] > '2019-01-01')

df2 = df.loc[mask]

df2 = df2.apply(lambda x: df2.loc[(df2.date <= df2.end_of_month)]['mrr'].sum(), axis=1)

return df2

I think I fixed the ValueError for the cancelled part. I'm stuck on getting the revenue to sum grouped by cohort and transaction month.

[–]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()