Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cohorts_touch = orders.query('device == "touch"').groupby(['first_order_month','cohort_lifetime']).agg({'buy_ts':'count','uid':'nunique'}).reset_index()
- cohort_touch_users_count = cohorts_touch[['first_order_month','uid']]
- cohort_touch_users_count = cohort_touch_users_count.rename(columns={'uid':'cohort_users'})
- cohorts_touch = cohorts_touch.merge(cohort_touch_users_count,on='first_order_month')
- cohorts_touch['rate'] = cohorts_touch['buy_ts'] / cohorts_touch['cohort_users']
- cohorts_pivot_touch = cohorts_touch.pivot_table(index='first_order_month',
- columns='cohort_lifetime',
- values='rate',
- aggfunc='mean').cumsum(axis=1)
- cohorts_pivot_touch.index = cohorts_pivot_touch.index.strftime("%m/%Y")
- plt.figure(figsize=(13, 9))
- plt.title('Среднее количество покупок в когорте на уникального мобильного пользователя')
- sns.heatmap(cohorts_pivot_touch, annot=True, fmt='.2f', linewidths=1, linecolor='gray')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement