How to calculate quarterly wise churn and retention rate with date column using python. with date column i want to group that quarterly using python.
This is used to calculate the churn count groupby quarterly
quarterly_churn_yes = out.loc[out['Churn'] == 'Yes'].groupby(out["Date"].dt.quarter).count()
print(quarterly_churn_yes["Churn"])
Date
1 1154
2 114
3 68
4 69
Name: Churn, dtype: int64
This is used to calculate the churn rate groupby quarterly
total_churn = out['Churn'].count()
print(total_churn)
quarterly_churn_rate = out.groupby(out["Date"].dt.quarter).apply(lambda x: quarterly_churn_yes["Churn"] / total_churn).sum()
print(quarterly_churn_rate)
Date
1 0.862159
2 0.085170
3 0.050803
4 0.051550
dtype: float64
The above code i have tried to the find churn rate grouped on date column querterly wise. I am getting 1,2,3,4 but i want year wise quarterly churn rate.
For example , if i have four years in the dataframe like 2018,2014,2017 in that
2008
1 1154
2 114
3 68
4 69
2014
1 1154
2 114
3 68
4 69
I think need:
For separate DataFrames by years is possible create
dictionary of DataFrames
:It contains no of months, it seems like 1 to 72.
I need to split tenure column into "range".
For example, this column contains 1 to 72 numbers, need to range up to 4 range.
here i found quarterlywise churn count and with that churn count later i found churn rate with churn count and total count.
Like this I need to find tenure wise 4 range to find churn count.