1圖 | 2圖 |
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['KaiTi','SimHei','FangSong'] #設(shè)置中文字體
df = pd.read_excel( "student.xlsx" )
df_err = df[ ▲ ]
請(qǐng)?jiān)凇幪钊牒线m的代碼。
km = ["語(yǔ)文","數(shù)學(xué)","英語(yǔ)","物理","化學(xué)","生物","政治","歷史","地理","技術(shù)"]
df1 = df . groupby( "班級(jí)" ) .
print( df1 ) #2圖所示
#刪除“姓名”和“科目數(shù)”列
df2 = df1 . drop(["姓名","科目數(shù)"] , axis = 1)
g = df2 . sum() #g為Series對(duì)象
#統(tǒng)計(jì)各科目的人數(shù)占總?cè)藬?shù)的比例
for k in km:
per = / len( df ) * 100
print(k , "比例為:" , round(per,2) , "%")
x =
y = g . values
plt.bar( x , y ) #3圖所示
plt.title("各科補(bǔ)弱比例對(duì)比")
plt.show()