SciPy Descriptive Stats
Published Feb 1, 2025
Contribute to Docs
In SciPy, descriptive statistics refers to summarizing and analyzing a dataset’s key characteristics. It helps summarize essential properties such as central tendency, variability, and distribution shape.
The .describe() function in the scipy.stats module is used to calculate common descriptive statistics of a given array, such as:
- Number of observations (
nobs) - Minimum and maximum values (
minmax) - Mean (
mean) - Variance (
variance) - Skewness (
skewness) - Kurtosis (
kurtosis)
Syntax
stats.describe(a, axis=0, ddof=1, bias=True, nan_policy='propagate')
a: The input data to describe.axis(Optional): The axis along which to compute the descriptive statistics (default is0). If set toNone, the statistics are calculated for the whole array.ddof(Optional): Delta Degrees of Freedom for calculating variance (default is1).bias(Optional): If set toFalse, it corrects the skewness and kurtosis calculations for statistical bias.nan_policy(Optional): Defines the handling method to use when the input contains NaN. The options include:propagate(Default): Returns NaN.raise: Raises an error.omit: Ignores NaN values and performs the calculations.
Example
The following example demonstrates the usage of the .describe() function to calculate the descriptive statistics of a given array:
import numpy as npfrom scipy import stats# Define an arrayarr = np.array([12, 23, 34, 45, 56])# Calculate the descriptive statistics of the arrayres = stats.describe(arr)# Print the resultprint(res)
The above code produces the following output:
DescribeResult(nobs=5, minmax=(12, 56), mean=34.0, variance=302.5, skewness=0.0, kurtosis=-1.3)
Codebyte Example
The following codebyte example demonstrates the usage of the .describe() function to calculate the descriptive statistics of a given array:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SciPy on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
- With Certificate
- Beginner Friendly.24 hours