🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEscipy

scipy Documentation

LOADING ENGINE...

stats.describe()

AI & DATA SCIENCE // stats-describe

scipy.stats.describe() computes a bundle of common summary statistics for a dataset in a single call — count, min/max, mean, variance, skewness, and kurtosis.

Syntax

scipy.stats.describe(a, ddof=1)

Deep Dive Course

describe() returns a single named-tuple-like result containing several statistics at once: nobs, number of observations, minmax, a tuple of the min and max, mean, variance, skewness, a measure of the distribution's asymmetry, and kurtosis, a measure of how heavy-tailed the distribution is compared to a normal distribution. Unlike NumPy's individual functions like np.mean() or np.var(), which each compute one statistic at a time, describe() bundles the most commonly needed ones together in one efficient pass over the data, similar in spirit to pandas' df.describe(), but returning skewness and kurtosis by default, which pandas' version doesn't.

1Understanding stats.describe()

describe() returns a single named-tuple-like result containing several statistics at once: nobs, number of observations, minmax, a tuple of the min and max, mean, variance, skewness, a measure of the distribution's asymmetry, and kurtosis, a measure of how heavy-tailed the distribution is compared to a normal distribution. Unlike NumPy's individual functions like np.mean() or np.var(), which each compute one statistic at a time, describe() bundles the most commonly needed ones together in one efficient pass over the data, similar in spirit to pandas' df.describe(), but returning skewness and kurtosis by default, which pandas' version doesn't.

💡

scipy.stats.describe()'s variance uses ddof=1, sample variance, dividing by N-1, by default, matching pandas' default, but differing from NumPy's np.var(), which defaults to ddof=0, population variance — be aware of this difference if you're cross-checking values between the two libraries.

editor.html
from scipy import stats
import numpy as np

data = np.array([2, 4, 4, 4, 5, 5, 7, 9])
result = stats.describe(data)
print(result.mean, result.variance)
localhost:3000

2Practical Example

Here is a real-world application of stats.describe() showing how it is used in production SciPy code.

editor.html
from scipy import stats
import numpy as np

data = np.array([1, 2, 2, 3, 3, 3, 4, 4, 4, 4])
result = stats.describe(data)
print(result.nobs, result.minmax)
localhost:3000

3Best Practices

Follow these guidelines when working with stats.describe():

1. Use describe() for a quick, one-call summary bundling several statistics together, instead of computing each one separately with individual functions

2. Interpret skewness and kurtosis relative to a normal distribution's reference values, skewness 0, excess kurtosis 0, rather than in isolation, since they're most meaningful as a comparison to normality

3. Be aware of the ddof default difference between scipy.stats' sample variance and NumPy's population variance default, when cross-checking values between the two

⚠️

Tip: scipy.stats.describe()'s variance uses ddof=1, sample variance, dividing by N-1, by default, matching pandas' default, but differing from NumPy's np.var(), which defaults to ddof=0, population variance — be aware of this difference if you're cross-checking values between the two libraries.

editor.html
from scipy import stats
import numpy as np

data = np.array([2, 4, 4, 4, 5, 5, 7, 9])
result = stats.describe(data)
print(result.mean, result.variance)
localhost:3000

Examples

Example 01Basic Usage
from scipy import stats
import numpy as np

data = np.array([2, 4, 4, 4, 5, 5, 7, 9])
result = stats.describe(data)
print(result.mean, result.variance)
Example 02Advanced Example
from scipy import stats
import numpy as np

data = np.array([1, 2, 2, 3, 3, 3, 4, 4, 4, 4])
result = stats.describe(data)
print(result.nobs, result.minmax)

Best Practices

  • Use describe() for a quick, one-call summary bundling several statistics together, instead of computing each one separately with individual functions
  • Interpret skewness and kurtosis relative to a normal distribution's reference values, skewness 0, excess kurtosis 0, rather than in isolation, since they're most meaningful as a comparison to normality
  • Be aware of the ddof default difference between scipy.stats' sample variance and NumPy's population variance default, when cross-checking values between the two

Interview Question

Why does scipy.stats.describe()'s reported variance differ from calling np.var() on the exact same data with default arguments?

Hint: Think about each function's default ddof value.

scipy.stats.describe() defaults to ddof=1, computing the sample variance by dividing the sum of squared deviations by N minus 1, which is the standard convention for treating the data as a sample used to estimate a larger population's variance. np.var() instead defaults to ddof=0, computing the population variance by dividing by N directly, appropriate when the data represents the entire population being described rather than a sample. Since the two functions default to different divisors, they report different variance values for the exact same data unless you explicitly match their ddof arguments.

Exercises

MediumPractice using stats.describe() in a real scenario.
View Solution
from scipy import stats
import numpy as np

data = np.array([2, 4, 4, 4, 5, 5, 7, 9])
result = stats.describe(data)
print(result.mean, result.variance)

Frequently Asked Questions

Why does scipy.stats.describe()'s reported variance differ from calling np.var() on the exact same data with default arguments?

scipy.stats.describe() defaults to ddof=1, computing the sample variance by dividing the sum of squared deviations by N minus 1, which is the standard convention for treating the data as a sample used to estimate a larger population's variance. np.var() instead defaults to ddof=0, computing the population variance by dividing by N directly, appropriate when the data represents the entire population being described rather than a sample. Since the two functions default to different divisors, they report different variance values for the exact same data unless you explicitly match their ddof arguments.

Related Functions

df-describenp-varnp-mean