Descriptive Statistic - GeeksforGeeks

22 Apr, 2020
In Descriptive statistics, we are describing our data with the help of various representative methods like by using charts, graphs, tables, excel files etc. In descriptive statistics, we describe our data in some manner and present it in a meaningful way so that it can be easily understood. Most of the times it is performed on small data sets and this analysis helps us a lot to predict some future trends based on the current findings. Some measures that are used to describe a data set are measures of central tendency and measures of variability or dispersion.
Types of Descriptive statistic:
Measure of central tendency
Measure of variability
Measure of central tendency:It represents the whole set of data by single value.It gives us the location of central points. There are three main measures of central tendency:
Mean
Mode
Median
Mean:It is the sum of observation divided by the total number of observations. It is also defined as average which is the sum divided by count.where, n = number of termsPython Code to find Mean in pythonimport numpy as np  # Sample Dataarr = [5, 6, 11]      # Meanmean = np.mean(arr)        print("Mean = ", mean)Output :Mean =  7.333333333333333
Mode:It is the value that has the highest frequency in the given data set. The data set may have no mode if the frequency of all data points is the same. Also, we can have more than one mode if we encounter two or more data points having the same frequency.Code to find Mode in pythonfrom scipy import stats  # sample Dataarr =[1, 2, 2, 3]       # Modemode = stats.mode(arr)      print("Mode = ", mode)Output:Mode =  ModeResult(mode=array([2]), count=array([2]))Median:It is the middle value of the data set. It splits the data into two halves. If the number of elements in the data set is odd then the centre element is median and if it is even then the median would be the average of two central elements.where, n=number of termsPython code to find Medianimport numpy as np  # sample Dataarr =[1, 2, 3, 4]      # Medianmedian = np.median(arr)     print("Median = ", median)Output:Median =  2.5
Measure of variability:Measure of variability is known as the spread of data or how well is our data is distributed. The most common variability measures are:RangeVarianceStandard deviationRange:The range describes the difference between the largest and smallest data point in our data set. The bigger the range, the more is the spread of data and vice versa.Range = Largest data value – smallest data valuePython Code to find Rangeimport numpy as np  # Sample Dataarr = [1, 2, 3, 4, 5]       #Finding MaxMaximum = max(arr)          # Finding Min Minimum = min(arr)   # Difference Of Max and Min          Range = Maximum-Minimum     print("Maximum = {}, Minimum = {} and Range = {}".format(        Maximum, Minimum, Range))Output:Maximum = 5, Minimum = 1 and Range = 4Variance:It is defined as an average squared deviation from the mean. It is being calculated by finding the difference between every data point and the average which is also known as the mean, squaring them, adding all of them and then dividing by the number of data points present in our data set.where N = number of termsu = MeanPython code to find Varianceimport statistics   # sample data arr = [1, 2, 3, 4, 5]     # varianceprint("Var = ", (statistics.variance(arr)))     Output:Var =  2.5Standard Deviation:It is defined as the square root of the variance. It is being calculated by finding the Mean, then subtract each number from the Mean which is also known as average and square the result. Adding all the values and then divide by the no of terms followed the square root.where N = number of termsu = MeanPython code to perform Standard Deviation:import statistics   # sample data arr = [1, 2, 3, 4, 5]     # Standard Deviationprint("Std = ", (statistics.stdev(arr)))    Output:Std = 1.5811388300841898References :Big Data WikipediaFormulaeMy Personal Notes
arrow_drop_upSave
Mean:It is the sum of observation divided by the total number of observations. It is also defined as average which is the sum divided by count.where, n = number of termsPython Code to find Mean in pythonimport numpy as np  # Sample Dataarr = [5, 6, 11]      # Meanmean = np.mean(arr)        print("Mean = ", mean)Output :Mean =  7.333333333333333

It is the sum of observation divided by the total number of observations. It is also defined as average which is the sum divided by count.
where, n = number of termsPython Code to find Mean in python
import numpy as np  # Sample Dataarr = [5, 6, 11]      # Meanmean = np.mean(arr)        print("Mean = ", mean)
Output :
Mean =  7.333333333333333

Mode:It is the value that has the highest frequency in the given data set. The data set may have no mode if the frequency of all data points is the same. Also, we can have more than one mode if we encounter two or more data points having the same frequency.Code to find Mode in pythonfrom scipy import stats  # sample Dataarr =[1, 2, 2, 3]       # Modemode = stats.mode(arr)      print("Mode = ", mode)Output:Mode =  ModeResult(mode=array([2]), count=array([2]))
Code to find Mode in python
from scipy import stats  # sample Dataarr =[1, 2, 2, 3]       # Modemode = stats.mode(arr)      print("Mode = ", mode)
Output:
Mode =  ModeResult(mode=array([2]), count=array([2]))
Median:It is the middle value of the data set. It splits the data into two halves. If the number of elements in the data set is odd then the centre element is median and if it is even then the median would be the average of two central elements.where, n=number of termsPython code to find Medianimport numpy as np  # sample Dataarr =[1, 2, 3, 4]      # Medianmedian = np.median(arr)     print("Median = ", median)Output:Median =  2.5
Measure of variability:Measure of variability is known as the spread of data or how well is our data is distributed. The most common variability measures are:RangeVarianceStandard deviationRange:The range describes the difference between the largest and smallest data point in our data set. The bigger the range, the more is the spread of data and vice versa.Range = Largest data value – smallest data valuePython Code to find Rangeimport numpy as np  # Sample Dataarr = [1, 2, 3, 4, 5]       #Finding MaxMaximum = max(arr)          # Finding Min Minimum = min(arr)   # Difference Of Max and Min          Range = Maximum-Minimum     print("Maximum = {}, Minimum = {} and Range = {}".format(        Maximum, Minimum, Range))Output:Maximum = 5, Minimum = 1 and Range = 4Variance:It is defined as an average squared deviation from the mean. It is being calculated by finding the difference between every data point and the average which is also known as the mean, squaring them, adding all of them and then dividing by the number of data points present in our data set.where N = number of termsu = MeanPython code to find Varianceimport statistics   # sample data arr = [1, 2, 3, 4, 5]     # varianceprint("Var = ", (statistics.variance(arr)))     Output:Var =  2.5Standard Deviation:It is defined as the square root of the variance. It is being calculated by finding the Mean, then subtract each number from the Mean which is also known as average and square the result. Adding all the values and then divide by the no of terms followed the square root.where N = number of termsu = MeanPython code to perform Standard Deviation:import statistics   # sample data arr = [1, 2, 3, 4, 5]     # Standard Deviationprint("Std = ", (statistics.stdev(arr)))    Output:Std = 1.5811388300841898References :Big Data WikipediaFormulaeMy Personal Notes
arrow_drop_upSave
where, n=number of termsPython code to find Median
import numpy as np  # sample Dataarr =[1, 2, 3, 4]      # Medianmedian = np.median(arr)     print("Median = ", median)
Output:
Median =  2.5

Measure of variability:Measure of variability is known as the spread of data or how well is our data is distributed. The most common variability measures are:
Range
Variance
Standard deviationRange:The range describes the difference between the largest and smallest data point in our data set. The bigger the range, the more is the spread of data and vice versa.Range = Largest data value – smallest data valuePython Code to find Rangeimport numpy as np  # Sample Dataarr = [1, 2, 3, 4, 5]       #Finding MaxMaximum = max(arr)          # Finding Min Minimum = min(arr)   # Difference Of Max and Min          Range = Maximum-Minimum     print("Maximum = {}, Minimum = {} and Range = {}".format(        Maximum, Minimum, Range))Output:Maximum = 5, Minimum = 1 and Range = 4Variance:It is defined as an average squared deviation from the mean. It is being calculated by finding the difference between every data point and the average which is also known as the mean, squaring them, adding all of them and then dividing by the number of data points present in our data set.where N = number of termsu = MeanPython code to find Varianceimport statistics   # sample data arr = [1, 2, 3, 4, 5]     # varianceprint("Var = ", (statistics.variance(arr)))     Output:Var =  2.5Standard Deviation:It is defined as the square root of the variance. It is being calculated by finding the Mean, then subtract each number from the Mean which is also known as average and square the result. Adding all the values and then divide by the no of terms followed the square root.where N = number of termsu = MeanPython code to perform Standard Deviation:import statistics   # sample data arr = [1, 2, 3, 4, 5]     # Standard Deviationprint("Std = ", (statistics.stdev(arr)))    Output:Std = 1.5811388300841898References :Big Data WikipediaFormulaeMy Personal Notes
arrow_drop_upSave
Range:The range describes the difference between the largest and smallest data point in our data set. The bigger the range, the more is the spread of data and vice versa.Range = Largest data value – smallest data valuePython Code to find Rangeimport numpy as np  # Sample Dataarr = [1, 2, 3, 4, 5]       #Finding MaxMaximum = max(arr)          # Finding Min Minimum = min(arr)   # Difference Of Max and Min          Range = Maximum-Minimum     print("Maximum = {}, Minimum = {} and Range = {}".format(        Maximum, Minimum, Range))Output:Maximum = 5, Minimum = 1 and Range = 4Variance:It is defined as an average squared deviation from the mean. It is being calculated by finding the difference between every data point and the average which is also known as the mean, squaring them, adding all of them and then dividing by the number of data points present in our data set.where N = number of termsu = MeanPython code to find Varianceimport statistics   # sample data arr = [1, 2, 3, 4, 5]     # varianceprint("Var = ", (statistics.variance(arr)))     Output:Var =  2.5Standard Deviation:It is defined as the square root of the variance. It is being calculated by finding the Mean, then subtract each number from the Mean which is also known as average and square the result. Adding all the values and then divide by the no of terms followed the square root.where N = number of termsu = MeanPython code to perform Standard Deviation:import statistics   # sample data arr = [1, 2, 3, 4, 5]     # Standard Deviationprint("Std = ", (statistics.stdev(arr)))    Output:Std = 1.5811388300841898
Range:The range describes the difference between the largest and smallest data point in our data set. The bigger the range, the more is the spread of data and vice versa.Range = Largest data value – smallest data valuePython Code to find Rangeimport numpy as np  # Sample Dataarr = [1, 2, 3, 4, 5]       #Finding MaxMaximum = max(arr)          # Finding Min Minimum = min(arr)   # Difference Of Max and Min          Range = Maximum-Minimum     print("Maximum = {}, Minimum = {} and Range = {}".format(        Maximum, Minimum, Range))Output:Maximum = 5, Minimum = 1 and Range = 4
The range describes the difference between the largest and smallest data point in our data set. The bigger the range, the more is the spread of data and vice versa.
Range = Largest data value – smallest data value
Python Code to find Range
import numpy as np  # Sample Dataarr = [1, 2, 3, 4, 5]       #Finding MaxMaximum = max(arr)          # Finding Min Minimum = min(arr)   # Difference Of Max and Min          Range = Maximum-Minimum     print("Maximum = {}, Minimum = {} and Range = {}".format(        Maximum, Minimum, Range))
Output:
Maximum = 5, Minimum = 1 and Range = 4
Variance:It is defined as an average squared deviation from the mean. It is being calculated by finding the difference between every data point and the average which is also known as the mean, squaring them, adding all of them and then dividing by the number of data points present in our data set.where N = number of termsu = MeanPython code to find Varianceimport statistics   # sample data arr = [1, 2, 3, 4, 5]     # varianceprint("Var = ", (statistics.variance(arr)))     Output:Var =  2.5
where N = number of termsu = MeanPython code to find Variance
import statistics   # sample data arr = [1, 2, 3, 4, 5]     # varianceprint("Var = ", (statistics.variance(arr)))     
Output:
Var =  2.5
Standard Deviation:It is defined as the square root of the variance. It is being calculated by finding the Mean, then subtract each number from the Mean which is also known as average and square the result. Adding all the values and then divide by the no of terms followed the square root.where N = number of termsu = MeanPython code to perform Standard Deviation:import statistics   # sample data arr = [1, 2, 3, 4, 5]     # Standard Deviationprint("Std = ", (statistics.stdev(arr)))    Output:Std = 1.5811388300841898
where N = number of termsu = MeanPython code to perform Standard Deviation:
import statistics   # sample data arr = [1, 2, 3, 4, 5]     # Standard Deviationprint("Std = ", (statistics.stdev(arr)))    
Output:
Std = 1.5811388300841898
References :Big Data WikipediaFormulae
statistical-algorithms
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Python Dictionary
Read a file line by line in Python
Enumerate() in Python
How to Install PIP on Windows ?
Iterate over a list in Python
Different ways to create Pandas Dataframe
Python String | replace()
Python program to convert a list to string
Reading and Writing to text files in Python
Create a Pandas DataFrame from Lists