Aasmajohn
Published in

Aasmajohn

Cohort Analysis: Using Python!

Source: https://content.webengage.com/wp-content/uploads/sites/4/2017/09/Easiest-Guide-to-Cohort-Analysis-1-1.png

What is a cohort?

  • number of users that downloaded the app in a given time period, or
  • number of users who canceled a subscription during the same month

Cohort Analysis

  • Help understand how user behaviors can affect one’s business, such as acquisition and retention
  • Understand customer churn
  • Calculate the customer lifetime value
  • Create more effective customer engagement

Types of cohorts:

  • Acquisition cohorts - these cohorts are based on when a user signs up or purchases the product. Acquisition cohorts help businesses figure out customer’s LTV, average churn time, and other retention related insights
  • Behavioral cohorts - the users are grouped on the basis of their behavior and actions they take in a given period of time. For example, a time when users install/uninstall the app, which features do users use the most, etc.

How to perform cohort analysis (in Python)?

Dataset snippet

Features:

Data Preprocessing:

B. Removing duplicate data:

C. Removing the NaN values:

Performing cohort analysis:

  • Invoice_day - indicates the date of the transaction by taking the first day of the month and year of InvoiceDate for each transaction
  • Cohort_month - indicates the date of the customer’s first transaction. To create this column we first group our dataset by “Customer ID” and then select the first purchase date by leveraging the min() function
Cohort Analysis Matrix

Interpreting the Cohort Analysis Matrix:

  • 2009–12–01: This is the “cohort” - customers who made a purchase in Dec of 2009
  • 955: This is the number of customers in this cohort. So 955 customers purchased products in Dec of 2009
  • 337: This is the number of customers who purchased again in the next month. So in Jan 2010, 337 customers made a purchase, and 618 did not

Calculating Retention Rate:

Retention rate heatmap

--

--

MSBA candidate at Columbia University

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store