In [43]:
import pandas as pd
import scipy.stats as st
import matplotlib.pyplot as plt
import numpy as np
df=pd.read_excel('survey2.xlsx')
print(df.columns)
Qs=['What kind(s) of Unit 1 work have you done? ','Which division(s) have you done Unit 1 work in?','I am a member of an equity-seeking group with respect to:']
Titles=['kinds_of_work','divisions','Equity']
names=[['TA','CI','CPO','AI','Access','TATP'],['Humanities','Socsci','Physsci','Lifesci','Indie'],['Gender','Sexual','Racial','Disability','Other','Prefer','None']]
A2=[['TA','CI','CPO','Invigilator','Invigilators','TATP'],['Humanities','Social','Physical','Life','Independent'],['Gender','Sexual','Racial','Disability','Other','Prefer','None']]
In [42]:
#print(df[df.columns[8]].value_counts())
for ii in range(0,len(Qs)):
Q=Qs[ii]
data=[]
P=[]
Pl=[]
Pw=[]
Pwl=[]
height=0.35
fig=plt.figure(figsize=(16,16),dpi=100)
ax1=plt.subplot(211)
ax2=plt.subplot(212)r
for jj in range(0,len(A2[ii])):
x=[]
xw=[]
A=A2[ii][jj]#As[ii][jj]
df2=df[(df[Q].str.contains(A))]
for kk in range(0,df2.shape[0]):
x.extend(df2.iloc[kk][4].replace(', I',';I').replace(', A',';A').replace(', D',';D').replace(', P',';P').replace(', N',';N').split(';'))
f=st.itemfreq(np.array(sorted(x,key=str.lower)))
ylabels=f[:,0]
ind = np.arange(len(ylabels))
xw=np.array(f[:,1]).astype(float)/np.sum(np.array(f[:,1]).astype(float))
x=np.array(f[:,1]).astype(float)#/np.sum(np.array(f[:,1]).astype(float))
if jj==0:
sw=np.zeros(np.shape(x))
s=np.zeros(np.shape(x))
P.append(ax1.barh(ind,x,height,left=s))
Pl.append(P[jj][0])
Pw.append(ax2.barh(ind,xw,height,left=sw))
Pwl.append(Pw[jj][0])
sw+=xw
s+=x
ax1.legend(Pl,(names[ii]))
ax1.set_yticks(ind)
ax1.set_yticklabels(ylabels)
ax2.legend(Pwl,(names[ii]))
ax2.set_yticks(ind)
ax2.set_yticklabels(ylabels)
plt.gcf().subplots_adjust(left=.5)
fig.savefig(Titles[ii]+'_non.png')
# plt.show()
In [41]:
#print(df[df.columns[8]].value_counts())
for ii in range(0,len(Qs)):
Q=Qs[ii]
data=[]
P=[]
Pl=[]
Pw=[]
Pwl=[]
height=0.35
fig=plt.figure(figsize=(16,16),dpi=100)
ax1=plt.subplot(211)
ax2=plt.subplot(212)
for jj in range(0,len(A2[ii])):
x=[]
xw=[]
A=A2[ii][jj]#As[ii][jj]
df2=df[(df[Q].str.contains(A))]
for kk in range(0,df2.shape[0]):
x.extend(df2.iloc[kk][1].replace(', I',';I').replace(', Crea',';Crea').replace(', Red',';Red').split(';'))
f=st.itemfreq(np.array(sorted(x,key=str.lower)))
ylabels=f[:,0]
ind = np.arange(len(ylabels))
xw=np.array(f[:,1]).astype(float)/np.sum(np.array(f[:,1]).astype(float))
x=np.array(f[:,1]).astype(float)#/np.sum(np.array(f[:,1]).astype(float))
if jj==0:
sw=np.zeros(np.shape(x))
s=np.zeros(np.shape(x))
P.append(ax1.barh(ind,x,height,left=s))
Pl.append(P[jj][0])
Pw.append(ax2.barh(ind,xw,height,left=sw))
Pwl.append(Pw[jj][0])
sw+=xw
s+=x
ax1.legend(Pl,(names[ii]))
ax1.set_yticks(ind)
ax1.set_yticklabels(ylabels)
ax2.legend(Pwl,(names[ii]))
ax2.set_yticks(ind)
ax2.set_yticklabels(ylabels)
plt.gcf().subplots_adjust(left=.5)
fig.savefig(Titles[ii]+'_fin.png')
# plt.show()