Finding Mean. Median and Mode without Libraries:

In this article, we will find the mean, median, and mode without using any external libraries in Python for Data Science.

  1. Mean: It is the average of all numbers and is also referr to as arithmetic mean. The code below will calculate the mean of a list that contains numbers.Find Mean, Median and Mode without Libraries in Python for Data Science
  2. Median: It is the number that is exactly in the middle in a group of numbers. The below code finds the median from a list of numbers.

Find Mean, Median and Mode without Libraries in Python for Data Science

  1. Mode: The number which occurs the most number of times in a given set of numbers is known as the mode. Code for calculation of mode for a list of numbers is given below.
    Find Mean, Median and Mode without Libraries in Python for Data Science

In the example, we have import the Counter from collections for calculating the duplicate element in the list.

We have define a list of numbers and length of the list. Now, we have then call the counter, which helps in counting the hashable objects and then convert them into dict objects. We have then initialize a for loop to compare all the dict values to max of all dict values and then it will return the element having the maximum count.

Conclusion:

We have the above programs for understanding the working, and it should not be there for coding in Python generally. We generally import the statistics library and use the in-built functions mean(), median() and mode() for calculation.

To learn more about mean, median and mode in python for data science. You can check this and this as well.

Leave a Reply

Your email address will not be published. Required fields are marked *