I have similar to the below dataframe and I would like to create a few summary stats around the behaviour of customers over time
pd.DataFrame([
['id1','23/5/2019','not_emailed']
,['id1','24/5/2019','not_emailed']
,['id1','25/5/2019','emailed']
,['id1','26/5/2019','emailed']
,['id1','27/5/2019','emailed']
,['id1','28/5/2019','emailed']
,['id1','29/5/2019','emailed']
,['id1','30/5/2019','emailed']
,['id1','31/5/2019','emailed']
,['id1','1/6/2019','emailed']
,['id1','2/6/2019','emailed']
,['id2','23/5/2019','not_emailed']
,['id2','24/5/2019','not_emailed']
,['id2','25/5/2019','emailed']
,['id2','26/5/2019','emailed']
,['id2','27/5/2019','emailed']
,['id3','29/5/2019','not_emailed']
,['id3','30/5/2019','emailed']
,['id3','31/5/2019','emailed']
,['id3','1/6/2019','emailed']
,['id3','2/6/2019','emailed']
,['id4','29/5/2019','not_emailed']
,['id4','30/5/2019','emailed']
,['id4','31/5/2019','emailed']
,['id4','1/6/2019','emailed']
,['id4','2/6/2019','emailed']
,['id4','2/7/2019','emailed']
,['id4','3/7/2019','emailed']
,['id4','4/7/2019','emailed']
],columns=['id','date','status'])
The main scenarios that could be observed in this data set are:
id1 emailed on 25th but not converted
id2 emailed on 27th and converted on 28th because we dont see any more logs for this id
id3 emailed on 30th and converted on 3rd because we dont see any more logs for this id
id4 emailed on 30th and converted on 3rd but churned againon the 2nd
I would like to get a summary of that information per day
How many emailed, how many converted, how many churned that had previously converted
A desired potential output could be:
pd.DataFrame([
['29/5/2019',10,3,1] ,
['30/5/2019',10,2,1]
],columns=['date','emailed_total','converted_total','churned_total']
)
Not that numbers above are random and don't reflect the stats of the first dataset shared
My approaches so far:
1) partially solves the problem: find first day of emailed calculate days passed since first group by the elapsed days and aggregate works but not for churn customers
2) loop through dates filter out unique ids emailed loop through dates in the future and calculate the differences between sets does the job but not very clean and pythonic