Stop rebuilding the same retail analyses from scratch. PyRetailScience gives your team pre-built, tested modules for segmentation, gain-loss, cross-shop, and more.
from pyretailscience.analysis.customer import TransactionChurn
# Analyze transaction churn
churn = TransactionChurn(df, churn_period=90)
churn.plot()
# Segment customers by value
from pyretailscience.segmentation.hml import HMLSegmentation
segments = HMLSegmentation(df)
Leverage pre-built functions designed specifically for retail analytics. From customer segmentations to gain-loss analysis, PyRetailScience provides over a dozen building blocks to tackle retail-specific challenges.
See Analysis Modules →
Built with extensive unit testing and best practices, PyRetailScience ensures the accuracy and reliability of your analyses. Confidently present your findings, knowing they're backed by a robust, well-tested framework.
Get Started →import pytest
from pyretailscience.analysis.customer import TransactionChurn
def test_churn_has_expected_columns(sample_df):
churn = TransactionChurn(sample_df, churn_period=90)
assert "churned_pct" in churn.purchase_dist_df.columns
assert churn.n_unique_customers == 1250
# 94% coverage across all modules
Standardized visualizations that are presentation-ready with a few lines of code. Waterfall, Venn, heatmap, time series, and more.
Browse Plot Gallery →
Loop analyses over different dimensions. Use the output of one analysis as input for another. Spend less time on data manipulation.
See Examples →# Do our analysis
dbp = customer.DaysBetweenPurchases(df)
# Define the churn period as the 80th percentile
churn_period = dbp.purchases_percentile(0.8)
# Use that in our plot title
plot_title = f"Customers churn within {round(churn_period)} Days"
# Plot our chart
dbp.plot(title=plot_title)
Install PyRetailScience and run your first analysis in under a minute.
from pyretailscience.analysis.customer import (
PurchasesPerCustomer,
)
# Analyze purchase distribution
ppc = PurchasesPerCustomer(df)
ppc.plot()
# → A publication-ready chart, instantly.