In [1]:
import pandas as pd
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
In [2]:
data = pd.read_csv('extract_medium.csv',sep=';')
In [3]:
data.head(1)
Out[3]:
In [4]:
Genders = ['Male','Female']
Education = ['Not in universe (Under 3 years)','No schooling completed','Nursery school to 4th grade',\
'5th grade or 6th grade','7th,8th grade','9th grade','10th grade','11th grade','12th grade,no diploma',\
'High school graduate','college,less than 1 year','college 1+ years, no degree','Associate degree','Bachelor,s degree',\
'Master.s degree','Professional degree','Doctorate degree']
MarriageState=['married','Widowed','Divorced','Separated','Never married']
In [77]:
table = pd.pivot_table(data,values='Earnings',index=['Sex', 'Education'],aggfunc=np.mean)
##OR###
temp1 = data.groupby(['Sex', 'Education']).Earnings.mean()
In [78]:
temp1
Out[78]:
In [79]:
temp1 = temp1.values
test=temp1.reshape(2,17)
In [80]:
test.shape
Out[80]:
In [82]:
fig = plt.figure()
ax = fig.add_subplot(111)
ax.pcolor(test,cmap=plt.cm.Reds,vmin=np.min(test), vmax=np.max(test))
ax.set_yticks([1,2])
ax.set_yticklabels(Genders)
ax.set_xticks(range(1,18))
ax.set_xticklabels(Education)
for tick in ax.get_xticklabels():
tick.set_rotation(90)
plt.gcf().subplots_adjust(bottom=0.20)
ax.set_title('Heat map of average Earnings Gender Vs Education')
plt.show()
plt.close()
In [68]:
table = pd.pivot_table(data,values='Earnings',index=['Sex', 'Marriage'],aggfunc=np.mean)
table = table.values
test=table.reshape(2,5)
In [74]:
fig = plt.figure()
ax = fig.add_subplot(111)
ax.pcolor(test,cmap=plt.cm.Reds,vmin=np.min(test), vmax=np.max(test))
ax.set_yticks([1,2])
ax.set_yticklabels(Genders)
ax.set_xticks(range(6))
ax.set_xticklabels(MarriageState)
for tick in ax.get_xticklabels():
tick.set_rotation(45)
plt.gcf().subplots_adjust(bottom=0.20)
ax.set_title('Heat map of average Earnings Gender Vs Mariage')
plt.show()
plt.close()
In [35]:
table = pd.pivot_table(data,values='Earnings',index=['Sex', 'Marriage','Hours'],aggfunc=np.mean)
In [36]:
type(table)
Out[36]: