MAHMOUD ABDELNABY
Automation · CLI SCRIPT · 2

E-Commerce RFM Customer Segmentation Engine in Python

Segment your e-commerce customers into VIPs, Promising, and At-Risk tiers using automated RFM analysis on your order exports.

Problem it addresses

Develop a pure Python RFM customer segmentation tool (rfm_engine.py): 1) Parses e-commerce order CSV exports (Customer ID, Order Date, Order Value), 2) Computes Recency, Frequency, and Monetary quintiles (1-5), 3) Assigns actionable customer segment labels (Champions, Loyal Customers, Potential Loyalists, At-Risk, Hibernating, Lost), 4) Outputs segmented CSVs and visual HTML summary charts.

Who it is for

PRO operating in high-growth e-commerce, digital publishing, and direct-response marketing across Saudi Arabia, UAE, and Egypt.

What is inside

Key files listed in the README repository architecture:

  • examples/salla_orders_sample.csv
  • LICENSE
  • playbooks/rfm-campaign-playbook.md
  • playbooks/segment-retention-playbook.md
  • README.md
  • reports/rfm_segment_summary.html
  • reports/rfm_segments_summary.html
  • sample_data/orders_sample.csv
  • src/rfm_calculator.py
  • src/rfm_engine.py
  • tests/test_rfm.py

How to evaluate and use it

  1. Read the README first and confirm that the documented problem matches your use case.
  2. Inspect the listed files to find the data, tools, templates, and tests relevant to your task.
  3. Follow the repository’s Quick Start and check prerequisites before running commands.
  4. Compare outputs with documented examples and review limitations before using them in a decision or client workflow.

Quick Start from the README: python -m unittest discover -s tests · python src/rfm_calculator.py --help

Scope and limitations

  • Recency, Frequency, Monetary Quantiles: Computes quintile scores (1-5) across transactional order histories to classify customers into actionable lifecycle cohorts.
  • Cohort Definitions: Maps numerical scores into 11 standard segments (Champions, Loyal Customers, Potential Loyalists, At Risk, Hibernating, Lost).
  • Currency & Timeframe Normalization: Adjusts monetary scoring for local currencies and enforces trailing 365-day rolling analysis windows.

This page summarizes the available documentation; it does not establish performance or business results. Verify data and prerequisites before use.

Related repositories