Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find Median [duplicate]

Tags:

python

median

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
like image 646
user1335606 Avatar asked May 07 '12 12:05

user1335606


People also ask

How do you find the median if there are 2 medians?

To find the median, calculate the mean by adding together the middle values and dividing them by two.

What is the formula to find the median?

Median formula when a data set is even Determine if the number of values, n, is even. Locate the two numbers in the middle of the data set. Find the average of the two middle numbers by adding them together and dividing the sum by two. The result of this average is the median.

How do you find the mean of repeated data?

Take these two steps to calculate the mean: Step 1: Add all the scores together. Step 2: Divide the sum by the number of scores used.


1 Answers

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

>>> from statistics import median
>>> median([1, 3, 5])
 3
like image 70
jabaldonedo Avatar answered Sep 30 '22 14:09

jabaldonedo