1图 | 2图 |
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['KaiTi','SimHei','FangSong'] #设置中文字体
df = pd.read_excel( "student.xlsx" )
df_err = df[ ▲ ]
请在▲处填入合适的代码。
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()