Session Ready
Exercise

Average purchase price by cohort

Building on the previous exercise, let's look at the same KPI, average purchase price, and a similar one, median purchase price, within the first 28 days. Additionally, let's look at these metrics not limited to 28 days to compare.

We can calculate these metrics across a set of cohorts and see what differences emerge. This is a useful task as it can help us understand how behaviors vary across cohorts.

Note that in our data the price variable is given in cents.

Instructions 1/3
undefined XP
  • 1
  • 2
  • 3

Use np.where to create an array month1 containing:

  • the price of the purchase purchase, if

    1. the user registration .reg_date occurred at most 28 days ago (i.e. before max_reg_date), and

    2. the date of purchase .date occurred within 28 days of registration date .reg_date;

  • NaN, otherwise.