数据整理并修正后,分析各班各科目的选择人数,以及各科目选择人数占总人数比例。km = ["语文","数学","英语","物理","化学","生物","政治","历史","地理","技术"]
df1 = df . groupby( "班级" ) .
print( df1 ) #2图所示
#删除“姓名”和“科目数”列
df2 = df1 . drop(["姓名","科目数"] , axis = 1)
g = df2 . sum() #g为Series对象
#统计各科目的人数占总人数的比例
for k in km:
per = / len( df ) * 100
print(k , "比例为:" , round(per,2) , "%")
x =
y = g . values
plt.bar( x , y ) #3图所示
plt.title("各科补弱比例对比")
plt.show()