Login
📚 Python for Introductory Statistics
Chapters ▾

Min and Max

To find the minimum and maximum values of a data set, you can use the list method or numpy as follows:

x = [x1, x2, x3, ...]

max(x)             # list max x is a Python list
min(x)             # list min

np.amax(x)         #Numpy max x is numpy array
np.amin(x)         #Numpy min

Example: The dataset below is scores of 20 students in a stat class. Find the minimum and maximum scores.

81, 21, 53, 32, 80, 13, 26, 42, 35, 41, 14, 25, 87, 62, 46, 40, 32, 52, 85, 28, 17, 36, 83, 79, 18, 50, 17, 36, 36, 19

import numpy as np
x = [81, 21, 53, 32, 80, 13, 26, 42, 35, 41, 14, 25, 87, 62, 46, 40, 
             32, 52, 85, 28, 17, 36, 83, 79, 18, 50, 17, 36, 36, 19]

print('min is',np.amin(x))
print('max is',np.amax(x))
Show expected output
min is 13
max is 87

Example: Below is the list of ages of US Senators (2020). Write a pandas program to compute the minimum, 1st quartile, 2nd quartile, 3rd quartile and maximum age.

81,81,80,80,80,80,78,78,78,77,77,75,75,74,74,74,73,72,72,71,71,71,71,70,70, 70,70,68,68,68,68,68,67,67,67,66,66,65,65,65,65,64,64,64,64,64,64,63,63, 63,63,62,62,62,62,62,61,61,61,60,60,59,59,59,59,59,59,59,59,58,58,57,57, 56,56,55,54,54,54,54,54,53,53,52,52,52,52,52,51,50,49,48,46,45,44,43,43, 43,42,41

import numpy as n
x = [81,81,80,80,80,80,78,78,78,77,77,75,75,74,74,74,73,72,72,71,71,71,71,70,70,
        70,70,68,68,68,68,68,67,67,67,66,66,65,65,65,65,64,64,64,64,64,64,63,63,
        63,63,62,62,62,62,62,61,61,61,60,60,59,59,59,59,59,59,59,59,58,58,57,57,
        56,56,55,54,54,54,54,54,53,53,52,52,52,52,52,51,50,49,48,46,45,44,43,43,
        43,42,41]
print('the min age is', np.min(x))
print('the max age is', np.max(x))
print('the first quartile is',np.quantile(x,.25))
print('the second quartile is',np.quantile(x,.5))
print('the third quartile is',np.quantile(x,.75))
Show expected output
the min age is 41
the max age is 81
the first quartile is 55.75
the second quartile is 63.0
the third quartile is 70.0

Interpretation: the minimum, 1st quartile, 2nd quartile, 3rd quartile and maximum age are 41, 55.75, 63, 70 and 81 respectively.

Interpretation: The minimum score is 13 and the maximum score is 87

Adapted from Python for Introductory Statistics, by Simon Aman (Truman College, City Colleges of Chicago), licensed under CC BY 4.0. Changes were made: reformatted as an accessible XYZ web edition with live in-browser code cells. License: CC-BY-4.0.