IN PYTHON:
i have a list of integers:
[15299, 35279, 179, 89, 129, 415, 179, 129, 819, 999, 175, 549, 3755, 899, 399, 159, 159, 290, 499, 4549, 849, 390, 498, 13299, 499, 199, 119, 149, 257, 2549, 189, 189, 60, 1749, 899, 226, 399, 189, 186, 1099, 899, 499, 89, 415, 499]
i want to make a histogram and calculate summary statistics (mean, median, standard deviation, inner-quartile range, minimum, maximum, and any outliers) on this list of data.
Please find below the python code to calculating the statistics summary of the provided list along with the histogram
*Mean
*Median
*Mode
*Standard Deviation
*IQR(Inner Quartile Range)
We have used numpy module to calculate the needed statistics and matlabplot to draw the histogram. We have used formula to calculate the bin for the histogram plotting. Comments are provided along the code to help you understand better
Code
import numpy
import matplotlib.pyplot as plt
import math
from scipy import stats
list = [15299, 35279, 179, 89, 129, 415, 179, 129, 819, 999, 175, 549, 3755, 899, 399, 159, 159, 290, 499, 4549, 849, 390, 498, 13299, 499, 199, 119, 149, 257, 2549, 189, 189, 60, 1749, 899, 226, 399, 189, 186, 1099, 899, 499, 89, 415, 499]
#calculate the bin for histogram
length=len(list)
print("Length of the list is",length)
max_v=max(list)
print("max value in list is: ",max_v)
min_v=min(list)
print("min value in list is: ",min_v)
range_v=(max_v-min_v)
print("range in list is: ",range_v)
number=math.sqrt(length)
width=int(range_v/number)
#Calculating the statistics of the list
#Calculating the mean for the list
x=numpy.mean(list)
print("Mean for the list is : ",x)
#Calculating median for the list
y=numpy.median(list)
print("Median for the list is : ",y)
#Calculating mode for the list
z=stats.mode(list)
print("Mode for the list is : ",z)
#Calculating standard deviation for the list
st=numpy.std(list)
print("Standard Deviation for the list is : ",st)
#Calculating the InnerQuartile Range
sorted_list=sorted(list)
# First quartile (Q1)
Q1 = numpy.median(sorted_list[:int(length/2)])
# Third quartile (Q3)
Q3 = numpy.median(sorted_list[int(length/2):])
# Interquartile range (IQR)
IQR = Q3 - Q1
print("InnerQuartile Range is : ",IQR)
#drawing the histogram for the list
print("Drawing histogram for the list....")
plt.title("Histogram Figure")
plt.hist(list, bins = width)
plt.show()
Output
Note: If you like my answer, please review with thumbsup
Get Answers For Free
Most questions answered within 1 hours.