AI Hints
Home›Data Science Tutorial›More Sharp Tools
Data Science · Lesson 69 of 101

The 80/20 Rule

Checking it with real data.

⏱ 2 min read▶ Video at 1:57:35🎓 Free
Watch this lesson in the Data Science courseWatch on YouTube ↗Full Data Science course

In almost every strategy meeting, someone says that twenty percent of customers bring in eighty percent of the money. It sounds so wise that nobody checks. But you've got the data. So let's test it at Harbor Coffee.

The 80/20 Rule
From the video: The 80/20 Rule
  • Twenty percent, eighty percent
  • Nobody checks
  • Let's test it

How concentrated are we?

We add up profit by city, and by product, and we sort each one from highest to lowest. Cumulative sum gives us the running share of profit. Then we find the share from the top three cities. Next, customers. We rank them by monthly spend, and take the top twenty percent. Run it. Three products make fifty seven percent of the profit, and five of the eight make eighty one percent. The top three cities bring in only a third, so the cities are quite balanced. And the top twenty percent of customers make forty six percent of the money. That's well short of eighty. The rule is real as a shape, but its numbers are not a law.

pareto.pypython
import pandas as pd

s = pd.read_csv("sales.csv")
by_city = s.groupby("city")["profit"].sum().sort_values(ascending=False)
by_prod = s.groupby("product")["profit"].sum().sort_values(ascending=False)

print((by_prod / by_prod.sum()).cumsum().round(2).to_string())
print()
print("Top 3 of 12 cities:", round(by_city.head(3).sum() / by_city.sum(), 2))

c = pd.read_csv("customers.csv").drop_duplicates("customer_id")
c["monthly"] = c["visits_per_month"] * c["avg_spend"]
top = c["monthly"].sort_values(ascending=False)
print("Top 20% of customers:", round(top.head(len(top) // 5).sum() / top.sum(), 2))
Output
product
Latte         0.30
Flat White    0.44
Espresso      0.57
Sandwich      0.69
Mocha         0.81
Muffin        0.89
Tea           0.96
Cookie        1.00

Top 3 of 12 cities: 0.33
Top 20% of customers: 0.46

Why the shape matters

Knowing how concentrated you are changes your plan. If a few products make most of the profit, protect their supply first. If customers are balanced, then losing one isn't a disaster, and broad marketing can make sense. If one client is half your revenue, that's a serious risk. And always compare by profit, because a best seller can make little money.

Few productsprotect supply
Balanced customersbroad marketing
One huge clienta serious risk
Use profitnot only sales

Quick check

Your top ten percent of users create ninety percent of the posts. Your manager wants to ignore the others. What's the risk? Think about it. Those quiet users may be the audience that makes posting worthwhile. Concentration in one number doesn't tell you who really matters.

Quick check
What is the main risk?

Two better measures

Instead of quoting a rule, you can show the whole picture. A Lorenz curve plots the running share of money, against the running share of customers, and the further it bends, the more concentrated you are. The Gini number sums up that curve, from zero for perfectly equal, to one for a single customer holding everything. Track it each quarter. A steady rise warns you that you're leaning on fewer and fewer people.

Lorenz curvethe whole shape
Gini numberzero to one
Track iteach quarter
A rising Ginifewer people, more risk

Summary

Measure concentration, rather than quoting the rule. Next, let's make your work reliable, so that it runs without you.

Key takeaways
  • Test the rule on your data
  • Shape matters for risk
  • Compare by profit
Next up: Data Checks — catching problems automatically