python में statistics module का median() method का use दिए गए numeric data set का middle value calculate करता है। यह method median calculate करने से पहले data को ascending order में sort करता है।

What is median?

median का मतलब होता है किसी dataset का exactly middle value , जो कि integer या float किसी भी type की हो सकती है , हालाँकि या dataset पर depend करता है।

median को calculate करने से पहले उसे sort जरूर कर ले।


median formula

अगर set में present numbers की संख्या odd है , तब तो median सबसे बीच वाला होगा।
For Example : 3,4,5,66,7 का median 5 होगा ।

और अगर set में present numbers की संख्या even है , तब तो median ((n/2)th value + {(n/2) +1}th value)/2  होगा। जिसे कुछ इस तरह से calculate करते हैं।
Example : find median of 3,4,5,66,7,6.

Step 1. : sort data in ascending order => 3,4,5,6,7,66

Step 2. Find the n/2, (n/2)+1 => 5,6

Step 3. calculate of it's average => (5+6)/2 = 5.5

Python statistics median Method Syntax

statistics.median(data)

Parameters

  1. data | required : data जिसका हमें median calculate करना है , आप इसमें numeric values की list या कोई भी iterator (list, tuple, set) pass कर सकते हैं।

  2. Return value : pass की गयी values के according float value/Integer value return होती है।


Python statistics median Method Example

Copy Fullscreen Close Fullscreen Run
import statistics

#pass data in list.
print('Calculate using list')
print(statistics.median([23,34,546,67]))

#pass data in tuple.
print('Calculate using tuple')
print(statistics.median((3,4,5,66,7,6)))

#pass data in set.
print('Calculate using set')
print(statistics.median({23,34,546}))
Output
C:\Users\Rahulkumar\Desktop\python>python median.py
Calculate using list
50.5
Calculate using tuple
5.5
Calculate using set
34

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers