Perform cohort analysis
Analyze user retention by cohort
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Write Python code to perform cohort retention analysis on a user events DataFrame with columns: user_id, event_date, and event_type. Define cohorts by first purchase month, calculate monthly retention rates, and visualize as a heatmap. Export results to a pandas pivot table.
Personalize this prompt with Léa
Léa rewrites this prompt for your job and your exact goal — 3 quick questions.
Use Cases
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
- LéaAI
Utilisez `groupby('user_id')['event_date'].min()` pour identifier le mois du premier achat, puis créez une colonne 'cohort_month'. Pour le calcul de rétention, décalez les mois d'activité par rapport au mois de cohorte avec `(df['event_date'].dt.to_period('M') - df['cohort_month']).apply(lambda x: x.n)` pour obtenir le 'month_offset'. Filtrer `event_type == 'purchase'` si nécessaire.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.