Python Tutorial : Calculating KPIs - a practical example

Learn how to calculate first-week conversion rates for a subscription product using Python. The presenter filters users with full observation windows, finds a 23.2% conversion rate, then builds reusable functions to compare 7-day and 14-day windows across user cohorts like Android mail users.
Chapters
Congratulations. Now that we have mastered aggregating our data in interesting ways, let's put these techniques into practice. We will start by examining the KPI. In this case, we will look in the first week after the trial ends. Consider our current date to be March 17, 2018. To start we need to check what the maximum lapse date in our data set is which turns out to be today. Then we need to remove users who lapsed today or in any of the prior seven days. This ensures that everyone had a full seven days to potentially subscribe. We do this by filtering on the condition of our lapse date being less than the current date minus seven days. Next we count how big this filtered group is by calling the count method on the filtered data set. Then we need to find the number of users who subscribed within seven days of lapsing. We check this by seeing who has a non 0 subscription price and whose purchase is within 7 days of lapsing. We can filter in a similar way to before and then count the size of the resulting group. Finally, we need to divide our sub end user number by our total number to see we have a first week conversion rate of 23.2%. Now we want to check week one and week two conversion rates across different cohorts. We can exclude to near today as before. Since we can only aggregate over one column, we will create a column encoding our needed information. Here we add a column sub time that is the days between the lapse date and the subscription date if the user subscribed and nat otherwise. We do this with the numpy where method which takes a condition and a value to return if true and an alternative value to return if false and using this to check if there is a value present, I've created two functions GCR7 and GCR14 that take our sub time column and perform the steps we performed manually above to find the conversion rates in that period. To find the conversion rates we can now group by some key demographic fields and then call our functions unsubtime. Looking at our results as we can see we have fairly similar conversion rates with the exception of mails on Android being slightly higher generally. To conclude our discussion on KPIs, it is important to note that while there is an infinite number of KPIs, we want to choose carefully which to rely on. One factor in determining this is how long it takes to gain insight on a metric. To find monthly conversion rate we need to wait a month from the lapse date to determine if a user converted. This can make it impractical to monitor on an actionable time scale. Other ways to uncover KPIs include exploratory analysis that reveals relationships between metrics and behaviors or results. Additionally, these metrics can be tied to the business metrics and important in that way. In the KPIs calculated above, we may consider this metric important because if it changes, it serves as a warning of potential problems down the road. We will continue exploring this point in the next chapter by tracking this KPI over time. Further, measuring KPIs across groups is crucial because changes can impact groups in drastically different ways. There may be factors important to one group but not to another, and this is important to understand. Now you have a sense of why KPIs are useful and how to think about integrating them.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







