Python

Statistics

Online Courses
Complete Python Bootcamp: Go from zero to hero in Python

Statistics with Python
Using the math library you can get various statistical values. We start by creating a list of values:

 import math

x = [1,2,15,3,6,17,8,16,8,3,10,12,16,12,9]

Five number summary
We can get the five number summary using the math library. The five number summary contains: minimum, maximum, median, mean and the standard deviation.

 import math
import numpy

x = [1,2,15,3,6,17,8,16,8,3,10,12,16,12,9]

print(numpy.min(x))
print(numpy.max(x))
print(numpy.std(x))
print(numpy.mean(x))
print(numpy.median(x))


Boxplot
This code will create a boxplot:
 import matplotlib.pyplot as plt
import numpy as np

x = [1,2,15,3,6,17,8,16,8,3,10,12,16,12,9]

plt.boxplot(x)
plt.show()

Previous Post Next Post

Cookie policy | Privacy policy | ©