DESCRIBE
This function computes core descriptive statistics for a numeric dataset, including sample size, minimum, maximum, mean, variance, skewness, and kurtosis.
For observations x_1, x_2, \ldots, x_n, the reported mean and variance are based on:
\bar{x} = \frac{1}{n}\sum_{i=1}^{n} x_i, \quad s^2 = \frac{1}{n-\mathrm{ddof}}\sum_{i=1}^{n}(x_i-\bar{x})^2
The function flattens a 2D Excel range into one sample, ignores non-numeric entries, and returns all statistics in a single 2D row for spreadsheet output.
Excel Usage
=DESCRIBE(data, ddof, bias)
data(list[list], required): Table of numeric values to analyze.ddof(int, optional, default: 0): Delta degrees of freedom for variance calculation.bias(bool, optional, default: false): If True, calculations are not corrected for statistical bias.
Returns (list[list]): 2D list [[nobs, min, max, mean, var, skew, kurt]], or error string.
Example 1: Basic statistics with default parameters
Inputs:
| data | ddof | bias | ||
|---|---|---|---|---|
| 1 | 2 | 3 | 0 | false |
| 4 | 5 | 6 |
Excel formula:
=DESCRIBE({1,2,3;4,5,6}, 0, FALSE)
Expected output:
| Result | ||||||
|---|---|---|---|---|---|---|
| 6 | 1 | 6 | 3.5 | 2.91667 | 0 | -1.2 |
Example 2: Statistics with ddof=1 for sample variance
Inputs:
| data | ddof | bias | ||
|---|---|---|---|---|
| 1 | 2 | 3 | 1 | false |
| 4 | 5 | 6 |
Excel formula:
=DESCRIBE({1,2,3;4,5,6}, 1, FALSE)
Expected output:
| Result | ||||||
|---|---|---|---|---|---|---|
| 6 | 1 | 6 | 3.5 | 3.5 | 0 | -1.2 |
Example 3: Statistics with bias correction enabled
Inputs:
| data | ddof | bias | ||
|---|---|---|---|---|
| 1 | 2 | 3 | 0 | true |
| 4 | 5 | 6 |
Excel formula:
=DESCRIBE({1,2,3;4,5,6}, 0, TRUE)
Expected output:
| Result | ||||||
|---|---|---|---|---|---|---|
| 6 | 1 | 6 | 3.5 | 2.91667 | 0 | -1.26857 |
Example 4: Statistics for larger values dataset
Inputs:
| data | ddof | bias | ||
|---|---|---|---|---|
| 10 | 20 | 30 | 0 | false |
| 40 | 50 | 60 |
Excel formula:
=DESCRIBE({10,20,30;40,50,60}, 0, FALSE)
Expected output:
| Result | ||||||
|---|---|---|---|---|---|---|
| 6 | 10 | 60 | 35 | 291.667 | 0 | -1.2 |
Python Code
import math
from scipy.stats import describe as scipy_describe
def describe(data, ddof=0, bias=False):
"""
Compute descriptive statistics using scipy.stats.describe.
See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.describe.html
This example function is provided as-is without any representation of accuracy.
Args:
data (list[list]): Table of numeric values to analyze.
ddof (int, optional): Delta degrees of freedom for variance calculation. Default is 0.
bias (bool, optional): If True, calculations are not corrected for statistical bias. Default is False.
Returns:
list[list]: 2D list [[nobs, min, max, mean, var, skew, kurt]], or error string.
"""
def to2d(x):
return [[x]] if not isinstance(x, list) else x
try:
data = to2d(data)
if not isinstance(data, list) or not all(isinstance(row, list) for row in data):
return "Error: Invalid input: data must be a 2D list."
flat = []
for row in data:
for x in row:
try:
val = float(x)
if math.isfinite(val):
flat.append(val)
except (TypeError, ValueError):
continue
if len(flat) < 2:
return "Error: Invalid input: data must contain at least two numeric values."
if not isinstance(ddof, (int, float)) or int(ddof) != ddof or ddof < 0:
return "Error: Invalid input: ddof must be a non-negative integer."
if not isinstance(bias, bool):
return "Error: Invalid input: bias must be a boolean."
res = scipy_describe(flat, ddof=int(ddof), bias=bias)
out = [
int(res.nobs),
float(res.minmax[0]),
float(res.minmax[1]),
float(res.mean),
float(res.variance),
float(res.skewness),
float(res.kurtosis),
]
return [out]
except Exception as e:
return f"Error: {str(e)}"