python mean function code example
Example 1: how to calculate mean in python
import statistics
a = [1,2,3,4,5]
mean = statistics.mean(a)
Example 2: python mean
import numpy as np
np.mean(your_list)
np.median()
np.std()
np.var()
Example 3: mean python code
>>> import statistics
>>> statistics.mean([4, 8, 6, 5, 3, 2, 8, 9, 2, 5])
5.2
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: mean python code
>>> def my_mean(sample):
... return sum(sample) / len(sample)
...
>>> my_mean([4, 8, 6, 5, 3, 2, 8, 9, 2, 5])
5.2