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

📊Analyse de donnéesIntermediateAll AIs

Stock and inventory data analysis

Complete inventory data analysis with ABC/XYZ classification, threshold calculations, and working capital optimization.

663
📊Analyse de donnéesIntermediateAll AIs

Retention Analysis

Improve user retention

333

Engineer date features

Extract features from datetime columns

402
📊Analyse de donnéesIntermediateAll AIs

Automated weekly report generation

Design an automated weekly reporting system with intelligent comments and contextual alerts.

548