How can we group users by signup cohort month and evaluate how many return to place orders in month 1, month 2, and month 3?
Joining signup dates with order activity dates computes cohort month offsets for retention grid matrices.
SaaS and subscription analytics measuring customer retention and product-market fit over time.
df_cohorts = df_orders.join(df_users.select("user_id", col("signup_date").alias("cohort_start")), "user_id").withColumn("cohort_month", date_format("cohort_start", "yyyy-MM")).withColumn("activity_month", date_format("order_date", "yyyy-MM")).withColumn("month_offset", months_between(col("order_date"), col("cohort_start")).cast("int"))Practice typing production-grade PySpark code for Scenario: User Retention Cohort Analysis.