Screen Link: https://app.dataquest.io/m/468/business-metrics/8/churn-rate
DQ Code:
def get_customers(yearmonth):
year = yearmonth//100
month = yearmonth-year*100
date = dt.datetime(year, month, 1)
return ((subs["start_date"] < date) & (date <= subs["end_date"])).sum()
I couldn’t understand how this function works.
Specially the subs[“start_date”]. how will the function recognize which row to get to compare with date?
What tricks me is that this function will be applied to
churn["total_customers"] = churn["yearmonth"].apply(get_customers)
It’s totally understandable that it will iterate row by row, but how the function will iterate on subs[“start_date”] subs[“end_date”] ?