0% found this document useful (0 votes)
13 views2 pages

Statistics Module

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Statistics Module

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Import the module first:

import statistics

1. mean()

Returns the arithmetic mean (average) of data.

data = [10, 20, 30, 40]


print(statistics.mean(data)) # Output: 25

2. median()

Returns the median (middle value) of data.

data = [10, 20, 30]


print(statistics.median(data)) # Output: 20

3. median_low()

Returns the low median when the number of data points is even.

data = [10, 20, 30, 40]


print(statistics.median_low(data)) # Output: 20

4. median_high()

Returns the high median when the number of data points is even.

data = [10, 20, 30, 40]


print(statistics.median_high(data)) # Output: 30

5. mode()

Returns the most common data point.

data = [1, 2, 2, 3]
print(statistics.mode(data)) # Output: 2

6. multimode() (Python 3.8+)

Returns a list of the most frequently occurring values.

data = [1, 1, 2, 2, 3]
print(statistics.multimode(data)) # Output: [1, 2]

7. pstdev()

Population standard deviation.

data = [2, 4, 4, 4, 5, 5, 7, 9]
print(statistics.pstdev(data)) # Output: 2.0

8. pvariance()
Population variance.

data = [2, 4, 4, 4, 5, 5, 7, 9]
print(statistics.pvariance(data)) # Output: 4.0

9. stdev()

Sample standard deviation.

data = [2, 4, 4, 4, 5, 5, 7, 9]
print(statistics.stdev(data)) # Output: ~2.138

10. variance()

Sample variance.

data = [2, 4, 4, 4, 5, 5, 7, 9]
print(statistics.variance(data)) # Output: ~4.571

11. harmonic_mean()

Returns the harmonic mean of data.

data = [1, 2, 4]
print(statistics.harmonic_mean(data)) # Output: ~1.714

12. geometric_mean() (Python 3.8+)

Returns the geometric mean of data.

data = [1, 2, 4]
print(statistics.geometric_mean(data)) # Output: ~2.0

13. quantiles() (Python 3.8+)

Divides data into equal intervals.

data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
print(statistics.quantiles(data, n=4)) # Output: [3.0, 5.0, 7.0] (quartiles)

Summary Table:
Function Description
mean() Arithmetic average
median() Middle value
median_low() Lower middle value
median_high() Higher middle value
mode() Most frequent value
multimode() List of most frequent values
stdev() Sample standard deviation
variance() Sample variance
pstdev() Population standard deviation
pvariance() Population variance
harmonic_mean() Harmonic mean
geometric_mean() Geometric mean
quantiles() Breaks data into intervals

You might also like