Advertisement
Dodma

Untitled

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