calculate mean in python code example

Example 1: how to calculate mean in python

import statistics

a = [1,2,3,4,5]

mean = statistics.mean(a) 
#Similar for other values such as variance, standard deviation

Example 2: mean of a list python

import numpy as np
np.mean(list)
np.std(list)

Example 3: python mean

# Probably the most convenient set of statistics functions are found
# in the Numpy package

# Basic syntax:
import numpy as np
np.mean(your_list) # Calculate mean
np.median()	# Calculate median
np.std()	# Calculate standard deviation
np.var()	# Calculate variance

Example 4: mean python

import numpy as np
values=[1,10,100]
print(np.mean(values))
values=[1,10,100,np.nan]
print(np.nanmean(values))

Example 5: calculate mean on python

def calculate_mean(n):
    s = sum(n)
    N = len(n)
    
    mean = s / N
    
    return mean