STATS IN PYTHON
To Take a Mean Using Python You Just need to follow these steps:
#Mean
1-First you need to import numpy.2-Then take any variable suppose I take speed as a variable then enter your desire value.3-Take another variable I take x as a variable then write numpy.mean and the variable which you take for your values.
The code is :import numpyspeed = [99, 88, 76, 55, 44, 33,120, 33, 22, 56, 34, 22, 35]x = numpy.mean(speed)print(x)
The Output is:
55.15384615384615
#Median
1-First you need to import numpy2-Then take any variable suppose I take speed as a variable then enter your desire value.3-Take another variable I take x as a variable then write numpy.median and the variable which you take for your values.4-print variable xThe code is :
import numpyspeed = [99, 88, 76, 55, 44, 33,120, 33, 22, 56, 34, 22, 35, 99,88, 66, 100]x = numpy.median(speed)print(x)The Output is:
56.0
#Standard Deviation
1-First you need to import numpy2-Then take any variable suppose I take speed as a variable then enter your desire value.3-Take another variable I take x as a variable then write numpy.std and the variable which you take for your values.4-print variable xThe code is :
import numpyspeed= [86,87,88,87,85,86]x = numpy.std(speed)print(x)The Output is:
0.9574271077563381
#Value At Risk
1-First you need to import numpy2-Then take any variable suppose I take speed as a variable then enter your desire value.3-Take another variable I take x as a variable then write numpy.var and the variable which you take for your values.4-print variable x
The code is :
import numpyspeed = [32, 11, 33, 22, 77, 97]x = numpy.var(speed)print(x)The Output is:
954.2222222222222
#Percentile
1-First you need to import numpy2-Then take any variable suppose I take speed as a variable then enter your desire value.3-Take another variable I take x as a variable then write numpy.percentile and the variable which you take for your values.4-print variable x
The code is :
import numpyages = [5,31,43,50,41,7,11,8,39,55,2,6,37,27,70,20]x = numpy.percentile(ages, 50)print(x)The Output is:
29.0
#Mode
1-First you need to import stats from scipy(because numpy has no mode function)2-Then take any variable suppose I take speed as a variable then enter your desire value.3-Take another variable I take x as a variable then write numpy.mode and the variable which you take for your values.4-print variable x
The code is :
from scipy import statsspeed = [99, 88, 76, 55, 44, 33,120, 33,55,22,66,34,77, 22, 56, 34,11, 35, 99,88, 66, 100,120,11, 130]x = stats.mode(speed)print(x)The Output is:
ModeResult(mode=array([11]), count=array([2]))