Gradrate Histogram
Gradrate Histogram
September 6, 2023
1.2 Now let us import the data (.csv file must be in the same folder as the
.pynb file)
[2]: gradrate = pd.read_csv("eg01-05gradrate.csv")
gradrate.head()
[3]: 51
[4]: 3
[5]: gradrate.shape
[5]: (51, 3)
1
1.3 Histogram of the percentage of on-time HS graduates in the US
[6]: plt.hist(gradrate["PCTGRAD"])
plt.show()
[7]: plt.hist(gradrate["PCTGRAD"],bins=9)
plt.show()
2
[8]: #help(plt.hist)
[9]: plt.hist(gradrate["PCTGRAD"],bins=[70,72.5,75,77.5,80,82.5,85,87.5,90,92.5])
plt.show()
[10]: plt.hist(gradrate["PCTGRAD"],bins=[70,72.5,75,77.5,80,82.5,85,87.5,90,92.5])
plt.ylabel("Number of States")
plt.xlabel("Percentage of on-time HS graduates")
3
1.4 Using the library seaborn: sns.histplot: https://seaborn.pydata.org/generated/seaborn.h
[11]: import seaborn as sns
plt.show()
4
[13]: #help(sns.histplot)
5
[15]: p = sns.histplot(data=gradrate, x="PCTGRAD",binwidth=2.5,binrange=[70,92.5])
p.set(xlabel="Percentage of on-time HS graduates",
ylabel="Number of States",
title='Histogram')
plt.show()
6
7