Hello, readers! In this article, we will be focusing on 7 IMP functions of Python statistics module, in detail.
So, let us get started!
Python statistics module
Python provides us with numerous modules to deal and work with the data.
When it comes to mathematical modelling and statistical data analysis, Python provides us with statistics module to work with the numeric data values closely. With this module, we can easily deal with the numeric data and make out statistical predictions from the data values at once!
We would be focusing on some of the most prominent functions offered by statistics module in Python:
- mean() function
- median() function
- median_high() function
- median_low() function
- stdev() function
- _sum() function
- _counts() function
Let us now have a look at them one by one!
1. The mean() function
Mean is one of the most used statistical measure to understand the data at a glance. The mean value represents the overall estimation of the entire data at once.
statistics.mean() function enables us to get the value of mean from the set of numeric data values.
2. The median() function
Apart from mean, we often come across situations wherein we need a value that represents the middle section of the entire data. With
statistics.median() function, we can calculate the middle value for the data values.
3. The median_high() function
median_high() function of statistics module enables us to get the higher median value from the data values passed to it as arguments. The high median is especially useful when the data values are discrete in nature.
4. The statistics.median_low() function
median_low() function can be used to fetch the lowest of the median values from the set of data values. It is useful when the data is discrete in nature and when we need the exact data point rather than interpolation points.
5. The statistics.median_grouped() function
median_grouped() function returns the median of the grouped data values but with a stipulated condition. That is, it calculates the 50th percentile median values through interpolation.
6. The _sum() function of statistics
When it comes to accumulation of the data points passed as arguments, the _sum() function comes into the picture. With
_sum() function, we can get the summation of all the data values along with the count of all the data points passed to it.
7. The _counts() function
_counts() function, we can get the frequency of every data point from the set of values. That is, it counts the frequency of occurrence of every single data point and returns the count of every data value against the data values.
Implementation of statistics module
Let’s work on implementing the functions of the statistics module in Python
import statistics data = [10,203,20,30,40,50,60,70,80,100] res = statistics.mean(data) print("Mean: ",res) res = statistics.median(data) print("Median: ", res) res = statistics.median_grouped(data) print("50% value: ",res) res = statistics.median_high(data) print("Median High value: ",res) res = statistics.median_low(data) print("Median Low value: ", res) res = statistics.stdev(data) print("Standard Deviation: ",res) res = statistics._sum(data) print("Sum: ",res) res = statistics._counts(data) print("Count: ",res)
Mean: 66.3 Median: 55.0 50% value: 59.5 Median High value: 60 Median Low value: 50 Standard Deviation: 55.429735301150004 Sum: (<class 'int'>, Fraction(663, 1), 10) Count: [(10, 1), (203, 1), (20, 1), (30, 1), (40, 1), (50, 1), (60, 1), (70, 1), (80, 1), (100, 1)]
By this, we have come to the end of this topic. Feel free to comment below, in case you come across any question.
For more such posts related to Python Programming, Stay tuned with us.
Till then, Happy Learning! 🙂