Coderhouse goes global

🌍

Read more

What Is a Z-Score? How Data Analysts Standardize and Compare Values

AI Engineering

Build and ship real applications with LLMs, agents and automation.

8 weeks · Live online · View course →

Data Analytics

Go from zero to job-ready analyst with SQL, Python and BI tools.

10 weeks · Live online · View course →

Dan Patiño

AI Strategy & Innovation at Coderhouse

Data

What Is a Z-Score? How Data Analysts Standardize and Compare Values

What Is a Z-Score? How Data Analysts Standardize and Compare Values

A z-score (also called a standard score) tells you how far a value is from the average, measured in standard deviations. A z-score of 0 means the value is exactly at the mean, a z-score of 2 means it sits two standard deviations above it, and a z-score of -1.5 means it is one and a half standard deviations below. That simple rescaling makes it possible to compare values that live on completely different scales, like order value in dollars and session length in minutes.

Data analysts use z-scores every day, often without naming them: to flag unusual transactions, to compare performance across stores of different sizes, to standardize features before a machine learning model, and to understand where a single result falls inside a distribution. It builds directly on standard deviation, so if that concept is fresh, z-scores will feel natural.

The z-score formula

The formula is short:

z = (x − mean) / standard deviation

  • x is the value you want to evaluate.

  • mean is the average of the dataset (or the population mean, if you know it).

  • standard deviation measures how spread out the values are.

The sign tells you the direction (above or below average) and the size tells you how unusual the value is. Because the result has no units, a z-score of 2 means the same thing whether the original data was revenue, temperature or response time.

A worked example

Imagine an online store where daily orders have a mean of 200 and a standard deviation of 25. Yesterday the store received 260 orders.

z = (260 − 200) / 25 = 60 / 25 = 2.4

Yesterday was 2.4 standard deviations above a typical day. If daily orders are roughly normally distributed, that is unusual: only a small share of days would land that high by chance. An analyst would check whether a campaign, a pricing error or a tracking bug explains it before celebrating.

Now compare two sales reps in different regions. Rep A closed $90,000 in a region where the mean is $70,000 with a standard deviation of $10,000 (z = 2.0). Rep B closed $120,000 where the mean is $110,000 with a standard deviation of $20,000 (z = 0.5). Rep B sold more in absolute terms, but Rep A performed far better relative to their peers.

How to read a z-score

When data is approximately normal, the empirical rule gives a quick intuition:

  • About 68% of values have a z-score between -1 and 1.

  • About 95% fall between -2 and 2.

  • About 99.7% fall between -3 and 3.

That is why |z| > 3 is a common rule of thumb for flagging potential outliers. Keep in mind the rule only works well when the distribution is close to normal. Skewed data such as revenue per customer, where a few large accounts dominate, will produce many “extreme” z-scores that are actually normal for that business.

Z-scores for outlier detection

Z-scores are one of the first tools analysts reach for when detecting outliers, but they have a weakness: the mean and standard deviation are themselves pulled by extreme values. A single huge outlier inflates the standard deviation and can hide itself.

The NIST/SEMATECH e-Handbook of Statistical Methods notes this problem and also points out that in small samples the maximum possible z-score is limited to (n − 1)/√n. With 10 observations, no value can reach a z-score of 3, so a |z| > 3 rule will never flag anything. NIST recommends the modified z-score from Iglewicz and Hoaglin instead:

M = 0.6745 × (x − median) / MAD

Here MAD is the median absolute deviation: the median of the distances between each value and the median. Values with |M| > 3.5 are labeled as potential outliers. Because the median and MAD barely move when an extreme value appears, the modified z-score is much more robust. Either way, a flagged value is something to investigate, not something to delete automatically.

How to calculate z-scores in Excel, SQL and Python

Excel or Google Sheets

Use =STANDARDIZE(A2, AVERAGE(A:A), STDEV.S(A:A)), or write the formula directly: =(A2-AVERAGE(A:A))/STDEV.S(A:A).

SQL

Window functions make it a one-liner: (value - AVG(value) OVER ()) / STDDEV(value) OVER (). Add PARTITION BY region to standardize within each group.

Python

With pandas: df["z"] = (df["value"] - df["value"].mean()) / df["value"].std(). SciPy also offers scipy.stats.zscore; note that it uses the population standard deviation by default (ddof=0), while pandas uses the sample version (ddof=1), so results can differ slightly on small datasets.

When analysts use z-scores

  • Anomaly detection: flagging unusual days, transactions or sensor readings in monitoring dashboards.

  • Fair comparisons: ranking stores, reps or campaigns that operate at different scales.

  • Feature scaling: standardizing inputs so machine learning models that rely on distance or gradient descent treat every feature evenly.

  • Statistical tests: z-tests and the test statistics behind many significance tests are z-scores of an estimate. If you compare means of small samples, a t-test is usually the better choice.

FAQ

Can a z-score be negative?

Yes. A negative z-score simply means the value is below the mean. The magnitude, not the sign, tells you how unusual it is.

Is a z-score the same as a percentile?

No, but they are related. If the data is approximately normal, you can convert a z-score to a percentile using the normal distribution. A z-score of about 1.64 corresponds roughly to the 95th percentile.

Should I use the sample or population standard deviation?

Use the sample standard deviation when your data is a sample of a larger population, which is the usual case in business analysis. With large datasets the difference is negligible.

Keep learning with Coderhouse

Standardizing data is a small skill that unlocks better comparisons, cleaner models and faster anomaly detection. Explore the path that fits your goals:

  • Data Analytics Course — learn SQL, Python, statistics and dashboards to spot anomalies and compare performance with real business data.

  • Forward Deployed AI Engineering Course — learn to build, evaluate and deploy production AI systems, where feature scaling and anomaly detection are everyday tools.

  • GTM Engineer Course (waitlist) — join the waitlist for early access to the program focused on building AI-powered go-to-market systems, including scoring and pipeline monitoring.

Dan Patiño

I'm Dan Patiño, head of AI Strategy & Innovation at Coderhouse. My day-to-day work involves merging the tactical management of e-commerce (CRO, Email Marketing and SEO) with the development of disruptive solutions. I specialize in building internal AI-powered apps to automate tasks and boost innovation within the team. I firmly believe that technology is strategy's best ally. To dive deeper into my professional journey, I'll be waiting for you on my LinkedIn profile.