How to Find Average of List in Python?
Hi,
If you need to see an example of how to find average of list in python. We will look at examples of python list find average. I would like to show you python count average of list. you can understand the concept of how to find the average value of a list in python.
There are many ways to find an average list value in python. I will give you the following three examples to calculate an average of a list in python.
1. Sum of List divided by the length of List
2. using statistics Module
3. using NumPy library
Let's see one be one example.
You can use these examples with python3 (Python 3) version.
Example 1: Sum of List divide by length of List
main.py
myList = [10, 5, 23, 25, 14, 80, 71] # Find Average from List avg = sum(myList)/len(myList) print(round(avg,2))
Output:
32.57
Example 2: using statistics Module
main.py
from statistics import mean myList = [10, 5, 23, 25, 14, 80, 71] # Find Average from List avg = mean(myList) print(round(avg,2))
Output:
32.57
Example 3: using numpy library
main.py
from numpy import mean myList = [10, 5, 23, 25, 14, 80, 71] # Find Average from List avg = mean(myList) print(round(avg,2))
Output:
32.57
I hope it can help you...