Created
February 7, 2022 16:35
-
-
Save peacing/e5227114dacebfe6e13faaf9556d3024 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# group by month using the loan created date and calculate some stats off the grouped data | |
def group_functions(x): | |
d = {} | |
d['loan_app_count'] = x['loan_amount'].count() | |
d['loan_funded_count'] = x['funded_at'].count() | |
d['conversion_rate'] = max(x['funded_at'].count() / x['created_at'].count(), 0) | |
d['time_to_conversion_avg'] = x['time_to_conversion'].mean() | |
return pd.Series(d, index=['loan_app_count','loan_funded_count', | |
'conversion_rate', 'time_to_conversion_avg']) | |
monthly = loans_df.created_at.dt.to_period('M') | |
monthly_loan_stats = loans_df.groupby(monthly).apply(group_functions) | |
monthly_loan_stats.index.rename('created_at_month', inplace=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment