Page 297 - Ai_C10_Flipbook
P. 297
Let us take a look at some basic statistical tools used in Python:
Mean
It is the average of numeric data in a given dataset. So, sum of all the values divided by the number of values in
the given set.
It is calculated as:
Mean =
To calculate mean in Python:
[1]: import statistics
marks=[45,34,41,46,47,39,38,48,45,34,41,39,39]
m=statistics.mean(marks)
print("the average marks of the class :",round(m,2))
the average marks of the class : 41.23
Median
When the data is arranged in an ascending/descending order then median is the middle number in a given
dataset. If there are two middle numbers, the mean of these two numbers will give the median.
For odd number of dataset: N + 1 th term
2
N th N th
For even number of dataset: 2 term + 2 + 1 term
2
To calculate median in Python with odd number of values:
[1]: import statistics
marks=[45,34,41,46,47,39,38,48,45,34,41,39,39]
m=statistics.median(marks)
print("the middle value of the sorted marks in class :",m)
the middle value of the sorted marks in class : 41
To calculate median in Python with even number of values:
[1]: import statistics
marks=[40, 45,34,41,46,47,39,38,48,45,34,41,39,39]
m=statistics.median(marks)
print("the middle value of the sorted marks in class :",m)
the middle value of the sorted marks in class : 40.5
Mode
It is the most frequent value in a given dataset.
There is no formula for this:
Mode = The value in the data set that occurs most frequently
Advance Python (Practical) 295

