Let’s see how to calculate median in Python.
To calculate median we need to import statistics module.
Luckily there is dedicated function in statistics module to calculate median.
import statistics as s x = [1, 5, 7, 8, 43, 6] median = s.median(x) print("Median equals: " + str(median))
See also: how to calculate median in Pandas