How to find Median

user1335606 picture user1335606 · May 7, 2012 · Viewed 91.6k times · Source

I have data like this.

Ram,500
Sam,400
Test,100
Ram,800
Sam,700
Test,300
Ram,900
Sam,800
Test,400

What is the shortest way to fine the "median" from above data. My result should be something like...

Median = 1/2(n+1), where n is the number of data values in the sample.

Test 500
Sam 700
Ram 800

Answer

jabaldonedo picture jabaldonedo · Mar 17, 2014

Python 3.4 includes statistics built-in, so you can use the method statistics.median:

>>> from statistics import median
>>> median([1, 3, 5])
 3