# How to Perform Cohort Analysis for User Retention and Engagement Using PM-Skills

> Learn cohort analysis for user retention and engagement with the pm-data-analytics package. Transform raw data into retention heatmaps and actionable insights using a single command.

- Repository: [Pawel Huryn/pm-skills](https://github.com/phuryn/pm-skills)
- Tags: how-to-guide
- Published: 2026-06-13

---

**The pm-data-analytics package in the phuryn/pm-skills repository provides a complete skill-based workflow for cohort analysis that converts raw user data into retention heatmaps and actionable insights through a single `/analyze-cohorts` command.**

The phuryn/pm-skills repository ships a dedicated **pm-data-analytics** package that implements cohort analysis as a reusable skill. This system enables product managers to explore retention patterns without writing analytical code themselves. The implementation follows a declarative architecture defined in YAML front-matter and markdown descriptions, making it extensible for various data sources and retention metrics.

## Understanding the Cohort Analysis Skill Architecture

### Skill Definition and Workflow

The core logic resides in [`pm-data-analytics/skills/cohort-analysis/SKILL.md`](https://github.com/phuryn/pm-skills/blob/main/pm-data-analytics/skills/cohort-analysis/SKILL.md). This file defines a **five-step workflow**: data validation → quantitative analysis → visualisation → insight extraction → research recommendations.

The skill enumerates the required data schema and supported file formats (CSV, Excel, JSON). It specifies the visual assets that can be generated, including retention matrices, heatmaps, and adoption curves. Because the skill is declarative, other commands can reuse it without code modifications.

### Command Surface and Interface

The `/analyze-cohorts` command, documented in [`pm-data-analytics/commands/analyze-cohorts.md`](https://github.com/phuryn/pm-skills/blob/main/pm-data-analytics/commands/analyze-cohorts.md), serves as the CLI and chat-bot interface. This command handler orchestrates the interaction by forwarding payloads to the skill and capturing generated artefacts.

When invoked, the command prompts users to define cohort dimensions, retention events, granularity (daily, weekly, monthly), and time ranges. The underlying implementation runs a **pandas**-based pipeline for local data processing, or emits a SQL query when no data file is supplied.

## Running Cohort Analysis with the `/analyze-cohorts` Command

### Uploading a CSV File

To analyze existing data, upload a file and invoke the command:

```text
/analyze-cohorts [upload cohort_engagement.csv]

```

The system validates the schema, asks you to confirm the cohort definition and retention event, then returns a markdown report containing a retention heatmap and a reusable Python script.

### Text-Only Requests Without Data

For scenarios where data resides in a database, provide a natural-language description:

```text
/analyze-cohorts "Show retention trends for users who signed up in Q1 2024, grouped by acquisition channel, using weekly granularity."

```

The skill generates a SQL query to pull the required data, builds the cohort table, and outputs the same visual and narrative artefacts as file-based analyses.

### Requesting Reusable Python Scripts

To export the analysis logic for local execution:

```text
/analyze-cohorts
Upload: cohort_data.xlsx
Request: "Give me a Python script that calculates weekly retention and plots a line chart for each cohort."

```

The response includes a [`cohort_analysis.py`](https://github.com/phuryn/pm-skills/blob/main/cohort_analysis.py) file that you can run locally to reproduce the analysis on new data, ensuring reproducibility across your team.

## Data Processing Pipeline and Output Formats

The skill executes as a **pure-Python data-processing routine** with no external service dependencies. When processing uploaded files, it uses pandas to compute retention matrices and statistical summaries. For text-only requests, it constructs SQL queries that your database can execute.

Output artefacts include:
- **Structured markdown reports** with embedded visualisations
- **CSV files** containing raw cohort tables for further analysis
- **Python scripts** that replicate the exact analytical pipeline

The repository's top-level README at [`pm-data-analytics/README.md`](https://github.com/phuryn/pm-skills/blob/main/pm-data-analytics/README.md) lists this skill under the *Data analytics* section, providing a quick entry point for new users.

## Summary

- The **phuryn/pm-skills** repository provides a self-contained cohort analysis skill through the `pm-data-analytics` package.
- The **`/analyze-cohorts`** command supports CSV, Excel, and JSON uploads, as well as natural-language text requests.
- The **five-step workflow** covers validation, analysis, visualisation, insight extraction, and research recommendations.
- Outputs include **markdown reports**, **CSV artefacts**, and **ready-to-run Python scripts** that require no external services.

## Frequently Asked Questions

### What data formats does the cohort analysis skill support?

The skill accepts **CSV**, **Excel**, and **JSON** files for direct upload. When you provide a natural-language description instead of a file, the system generates a SQL query to retrieve data from your database, making it compatible with any data warehouse that supports standard SQL.

### Can I run cohort analysis without uploading any data?

Yes. You can invoke `/analyze-cohorts` with a text description of your data source and desired metrics. The skill constructs the appropriate SQL query, executes the cohort logic, and returns visualisations and reports without requiring a file upload.

### How does the skill generate reusable Python code?

When you request a script in your command input, the skill exports the underlying **pandas**-based pipeline as a standalone `.py` file. This script includes the data validation, cohort calculation, and plotting logic used for your specific analysis, allowing you to reproduce results on new datasets locally.

### Is this implementation dependent on external APIs or services?

No. According to the source code in [`pm-data-analytics/skills/cohort-analysis/SKILL.md`](https://github.com/phuryn/pm-skills/blob/main/pm-data-analytics/skills/cohort-analysis/SKILL.md), the skill is implemented as a **pure-Python** routine. The command handler processes everything locally using pandas, requiring no external analytics services or cloud dependencies.