https://app.dataquest.io/m/468/business-metrics/8/churn-rate

start_date occurred before the first day of then given month

end_date is later than the last day of the previous month

I do not understand the logic here

this would mean if given month is Jan , then the start_date is any date of any month in the previous year so jan-dec?

But end_date is later than the last day of the previous month so later than Dec31

but then that is current month?

```
import datetime as dt
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()**
churn["total_customers"] = churn["yearmonth"].apply(get_customers)
churn["churn_rate"] = churn["total_churned"] / churn["total_customers"]
churn["yearmonth"] = churn["yearmonth"].astype(str)
arange = __import__("numpy").arange
Ellipse = __import__("matplotlib").patches.Ellipse
ax = churn.plot(x="yearmonth", y="churn_rate", figsize=(12,6), rot=45, marker=".")
start, end = ax.get_xlim()
ax.get_xticks()
ax.set_xticks(arange(2, end, 3))
ax.set_xticklabels(yearmonths[2::3])
circle = Ellipse((35, churn.loc[churn.yearmonth == "201312", "churn_rate"].iloc[0]),
5, 0.065, color='sandybrown', fill=False
)
ax.add_artist(circle)
ax.xaxis.label.set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.get_legend().remove()
```

- create a function that takes as input an integer representing a month in the format
`yyyymm`

and returns the number of rows in`subs`

satisfying all of the following criteria:`start_date`

occurred before the first day of then given month`end_date`

is later than the last day of the previous month- Create a column in
`churn`

named`total_customers`

that is the result of applying the function created in the previous step to`churn["yearmonth"]`

.- Calculate the churn rate for each month:
- Divide the
`total_churned`

column by`total_customers`

- Assign the result to a column called
`churn_rate`

- Set
`yearmonth`

as a string type.- Use the commented code to plot the churn rate across time.