P
📊Analyse de donnéesIntermediateAll AIs

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

Analyze user retention by cohort

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

  • 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.

Go further

Similar Prompts

Data cleaning and preparation

Step-by-step guide to clean and standardize raw data before analysis in Excel or Google Sheets.

0499
📊Analyse de donnéesIntermediateAll AIs

Annual HR Report

HR Reporting

0225

Generate interaction features

Discover feature interactions

0217
📊Analyse de donnéesIntermediateAll AIs

Extract and structure HTML content

Extract structured data from HTML pages

0207