In [2]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from scipy.stats import norm
plt.style.use('fivethirtyeight')
In [3]:
kcse = pd.read_csv('KCSE_2016.csv')
kcse
Out[3]:
In [16]:
kcse.iloc[2][1:].index
Out[16]:
In [64]:
plt.figure(num=None, figsize=(8, 6), dpi=80, facecolor='w', edgecolor='k')
xes = [x for x in range(12)]
my_xticks = kcse.iloc[2][1:].index
plt.xticks(xes, my_xticks)
plt.plot(xes,kcse.iloc[2][1:], lw = 1.5, label='2016')
plt.plot(xes,kcse.iloc[5][1:], lw = 1.5, label='2015')
plt.plot(xes,kcse.iloc[8][1:], lw = 1.5, label='2014')
plt.plot(xes,kcse.iloc[11][1:], lw = 1.5, label='2013')
plt.plot(xes,kcse.iloc[14][1:], lw = 1.5, label='2012')
plt.plot(xes,kcse.iloc[17][1:], lw = 1.5, label='2011')
plt.plot(xes,kcse.iloc[20][1:], lw = 1.5, label='2010')
plt.ylabel('No. of Students')
plt.xlabel('Grades')
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.savefig('no_students.png', bbox_inches='tight')
plt.show()
In [38]:
newkcse = kcse.drop('Gender',1)
In [92]:
newkcse.sum(1)
Out[92]:
In [94]:
521240/45967*100
Out[94]:
In [39]:
newkcse = newkcse.div(newkcse.sum(1)/100,0)
In [93]:
newkcse.set_index(kcse['Gender'])
Out[93]:
In [65]:
plt.figure(num=None, figsize=(8, 6), dpi=80, facecolor='w', edgecolor='k')
xes = [x for x in range(12)]
my_xticks = newkcse.columns
plt.xticks(xes, my_xticks)
plt.plot(xes,newkcse.iloc[2], lw = 1.5, label='2016')
plt.plot(xes,newkcse.iloc[5], lw = 1.5, label='2015')
plt.plot(xes,newkcse.iloc[8], lw = 1.5, label='2014')
plt.plot(xes,newkcse.iloc[11], lw = 1.5, label='2013')
plt.plot(xes,newkcse.iloc[14], lw = 1.5, label='2012')
plt.plot(xes,newkcse.iloc[17], lw = 1.5, label='2011')
plt.plot(xes,newkcse.iloc[20], lw = 1.5, label='2010')
plt.ylabel('% of Students')
plt.xlabel('Grades')
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.savefig('per_students.png', bbox_inches='tight')
plt.show()