Descriptive statistics help us quickly understand the main features of data. They summarize data with simple numbers like mean, variance, and range.
Descriptive statistics (describe) in SciPy
from scipy.stats import describe result = describe(data, axis=0, ddof=1, bias=False, nan_policy='propagate')
data is your input array or list of numbers.
The describe function returns several statistics like count, mean, variance, skewness, and kurtosis.
from scipy.stats import describe result = describe([1, 2, 3, 4, 5])
import numpy as np from scipy.stats import describe data = np.array([[1, 2, 3], [4, 5, 6]]) result = describe(data, axis=0)
ddof=0.from scipy.stats import describe result = describe([1, 2, 3, 4, 5], ddof=0)
This program calculates and prints basic descriptive statistics for a list of temperatures.
from scipy.stats import describe # Sample data: daily temperatures in Celsius temperatures = [22, 21, 23, 22, 24, 25, 23, 22, 21, 20] # Get descriptive statistics stats = describe(temperatures) print(f"Count: {stats.nobs}") print(f"Mean: {stats.mean:.2f}") print(f"Variance: {stats.variance:.2f}") print(f"Min: {stats.minmax[0]}") print(f"Max: {stats.minmax[1]}") print(f"Skewness: {stats.skewness:.2f}") print(f"Kurtosis: {stats.kurtosis:.2f}")
The describe function ignores NaN values only if nan_policy is set accordingly.
Skewness tells if data is symmetric (0 means symmetric).
Kurtosis indicates if data has heavy or light tails compared to normal distribution.
Descriptive statistics give a quick summary of data using numbers.
Use scipy.stats.describe to get count, mean, variance, min, max, skewness, and kurtosis.
This helps understand data shape and spread before deeper analysis.
Practice
scipy.stats.describe function provide when applied to a dataset?Solution
Step 1: Understand the purpose of
This function is designed to give a quick summary of key statistics about the data.scipy.stats.describeStep 2: Identify the statistics returned
It returns count, mean, variance, minimum, maximum, skewness, and kurtosis, which describe data shape and spread.Final Answer:
Summary statistics like count, mean, variance, min, max, skewness, and kurtosis -> Option AQuick Check:
Descriptive stats = count, mean, variance, min, max, skewness, kurtosis [OK]
- Thinking it returns only mean and median
- Confusing it with plotting functions
- Expecting a list of unique values
describe from scipy.stats?Solution
Step 1: Check correct import syntax for a function
Functions are imported usingfrom module import functionsyntax in Python.Step 2: Verify usage of
After importing, calldescribeafter importdescribe(data)directly.Final Answer:
from scipy.stats import describe; result = describe(data) -> Option AQuick Check:
Correct import and call = from scipy.stats import describe; result = describe(data) [OK]
- Using wrong import syntax like 'import describe from ...'
- Importing scipy.stats but not calling with module prefix
- Importing from wrong module
import numpy as np from scipy.stats import describe data = np.array([2, 4, 6, 8, 10]) result = describe(data) print(result.mean, result.minmax[0])
Solution
Step 1: Calculate the mean of the data array
The data is [2, 4, 6, 8, 10]. Mean = (2+4+6+8+10)/5 = 30/5 = 6.0.Step 2: Identify the minimum value from
minmaxminmaxreturns (min, max). The minimum is 2.Final Answer:
6.0 2 -> Option CQuick Check:
Mean = 6.0, Min = 2 [OK]
- Calculating mean incorrectly as 5.0
- Confusing minmax tuple order
- Assuming min is 0 without checking data
from scipy.stats import describe data = [1, 2, 3, 4, 5] result = describe(data, axis=1) print(result)
Solution
Step 1: Understand the data shape and axis parameter
The data is a 1D list. Axis=1 means operate along columns of 2D or higher arrays.Step 2: Identify the error caused by axis=1 on 1D data
Using axis=1 on 1D data causes an AxisError because axis 1 does not exist.Final Answer:
Axis=1 is invalid for 1D data, causing an error -> Option DQuick Check:
Axis must exist in data shape [OK]
- Assuming axis=1 works for 1D data
- Thinking data must be numpy array for describe
- Ignoring Python 3 print syntax
data = [0, -1, 2, 3, 4]. Using scipy.stats.describe, which statistic helps you understand if the data distribution is skewed?Solution
Step 1: Recall what skewness measures
Skewness shows if data is symmetric or leans left/right (skewed).Step 2: Identify which statistic indicates skewness
Among the options, only skewness directly measures data asymmetry.Final Answer:
Skewness -> Option BQuick Check:
Skewness = data asymmetry [OK]
- Confusing variance with skewness
- Thinking count or minimum show skewness
- Ignoring negative and zero values impact
Ready to prove it?
Pass the test and this pattern moves unknown
