A Denver retail client asked me to flag days where online sales looked unusual, and SciPy stats zscore handled it in one line.
The catch: SciPy and pandas don’t agree on the standard deviation, so one day can get two scores.
Quick answer: call scipy.stats.zscore(data). It returns (x - mean) / std per value, with ddof=0 by default:
from scipy import stats
z = stats.zscore([1240.50, 1310.25, 4890.00])
In this tutorial, you’ll learn scipy stats zscore options, outlier checks, zmap() and gzscore(). I ran it all on Python 3.12.5, NumPy 2.5.3 and SciPy 1.18.1.
Calculate z-scores with scipy.stats.zscore()
Every example imports these 14 days of sales from store.py:
# Daily online sales (USD), Denver store, Nov 16-29, 2026
import numpy as np
days = np.arange("2026-11-16", "2026-11-30", dtype="datetime64[D]")
sales = np.array([1240.50, 1310.25, 1185.75, 1402.00, 1275.30,
1350.80, 1198.40, 1288.65, 1322.10, 1265.95,
1230.40, 4890.00, 1505.20, 1288.90])
from scipy import stats
from store import days, sales
z = stats.zscore(sales)
print(z.round(2))
print("Highest:", days[z.argmax()], f"z = {z.max():+.2f}")
Output:
[-0.34 -0.26 -0.4 -0.16 -0.3 -0.22 -0.38 -0.29 -0.25 -0.31 -0.35 3.59
-0.05 -0.29]
Highest: 2026-11-27 z = +3.59

Black Friday scores +3.59. The spike lifts the mean, so normal days dip below zero. For the spread itself, see standard deviation in Python.
Why don’t SciPy z-scores match pandas? (ddof)
SciPy divides by n (ddof=0); pandas Series.std() divides by n - 1. So Black Friday scores 3.5922 in SciPy but 3.4615 with the pandas formula.
stats.zscore(sales, ddof=1) # matches pandas and Excel STDEV.S
With ddof=1, SciPy returns 3.4615 too. The broader SciPy stats module uses the same convention.
How does the zscore axis parameter work on a 2D array?
axis=0 (the default) scores each column, axis=1 each row, and axis=None the whole array as one sample. Rows here are three US cities:
import numpy as np
from scipy import stats
# Highs (F) for Nov 2-6, 2026: Phoenix, Chicago, Miami
temps = np.array([[78, 81, 76, 84, 79],
[52, 47, 58, 44, 50],
[83, 84, 82, 85, 83]])
print("axis=1 (each city):\n", stats.zscore(temps, axis=1).round(2))
z_all = stats.zscore(temps, axis=None)
print("Chicago, Nov 4:", z_all[1, 2].round(2), "with axis=None")
Output:
axis=1 (each city):
[[-0.59 0.51 -1.32 1.61 -0.22]
[ 0.38 -0.67 1.64 -1.31 -0.04]
[-0.39 0.59 -1.37 1.57 -0.39]]
Chicago, Nov 4: -0.86 with axis=None

For “was Chicago unusually cold this week?” use axis=1. With axis=None, Chicago’s warmest day still scores negative because it’s colder than the others. For min-max scaling instead, see normalizing a NumPy array.
Handle missing values with zscore nan_policy
By default, one missing day gives you all NaN. nan_policy takes 'propagate', 'omit' or 'raise':
import numpy as np
from scipy import stats
sales = np.array([1240.50, np.nan, 1185.75, 1402.00, 1275.30])
print("propagate:", stats.zscore(sales).round(2))
print("omit :", stats.zscore(sales, nan_policy="omit").round(2))
try:
stats.zscore(sales, nan_policy="raise")
except ValueError as err:
print("raise :", err)
Output:
propagate: [nan nan nan nan nan]
omit : [-0.45 nan -1.13 1.59 -0.01]
raise : The input contains nan values

omit scores the other four days; raise stops with a ValueError. I’d use omit for reports, raise in pipelines.Find outliers with z-scores
The common rule flags |z| > 3. Same sales data, filtered and plotted:
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
from store import days, sales
z = stats.zscore(sales)
flag = np.abs(z) > 3
print("Outlier days:", days[flag], sales[flag])
print(f"Mean without it: ${sales[~flag].mean():,.2f}")
plt.bar([str(d)[5:] for d in days], z,
color=np.where(flag, "crimson", "steelblue"))
plt.axhline(3, ls="--", color="gray")
plt.title("Denver store daily sales z-scores, Nov 2026")
plt.xticks(rotation=45)
plt.tight_layout(); plt.show()
Output:
Outlier days: ['2026-11-27'] [4890.]
Mean without it: $1,297.25

Without it, the average falls to $1,297.25. Check it’s an error before you drop it. To compare two groups, try SciPy ttest_ind.
Score new data with zmap() and skewed data with gzscore()
zmap(scores, compare) judges new values by a baseline’s mean and spread. gzscore() works on logs, for skewed positive data:
import numpy as np
from scipy import stats
from store import sales
baseline = np.delete(sales, 11) # November without Black Friday
december = np.array([1295.40, 2410.75, 1150.20])
print("zmap :", stats.zmap(december, baseline).round(2))
orders = np.array([42.10, 18.75, 65.30, 27.90, 310.00, 35.60])
print("zscore :", stats.zscore(orders).round(2))
print("gzscore:", stats.gzscore(orders).round(2))
Output:
zmap : [-0.02 13.43 -1.77]
zscore : [-0.4 -0.63 -0.18 -0.54 2.21 -0.47]
gzscore: [-0.19 -1.09 0.29 -0.65 2.03 -0.38]
December’s $2,410.75 day scores 13.43. The $310.00 order drops from 2.21 to 2.03 with gzscore() because logs squeeze long tails. For normal-curve probabilities, see scipy.stats.norm.
Common z-score errors and how to fix them
With ddof=0, no value in n points can exceed sqrt(n - 1). A $9,999 day in an 8-day week only reaches 2.645, so |z| > 3 never fires. Lower your threshold, or check skewness first.
If every value is equal, you get NaN plus a warning. Check np.ptp(data) > 0 first.
Four more SciPy statistics guides pair well with z-scores:
Frequently asked questions
What does scipy.stats.zscore return?
An array shaped like the input with (x - mean) / std per value.
Does scipy.stats.zscore use the sample or population standard deviation?
Population (ddof=0). Pass ddof=1 to match pandas.
How do I compute z-scores for each row?
Pass axis=1.
How do I ignore NaN values in zscore?
Use nan_policy="omit".
What is the difference between zscore and zmap?
zmap() scores new values against a separate baseline.
Where is scipy.stats.zscore documented?
See scipy.stats.zscore in the SciPy docs.

Bijay Kumar is a 13-time Microsoft MVP with more than 18 years in software development, and the founder of Python Guides and TSinfo Technologies. He started out building .NET and SharePoint solutions at HP, TCS and KPIT before moving into Python, machine learning and AI, and he also builds web apps with TypeScript and React. He writes the tutorials here himself, and every example is run before publishing so you see the real output. More about Bijay · Microsoft MVP profile · LinkedIn