第一步: 安装pandas
pip install pandas
第二步 安装matplotlib
pip install matplotlib
第三步使用以下代码
import pandas as pd
import matplotlib.pyplot as plt #画图
#xlrd报错的话, 使用引擎 engine="openpyxl"
df = pd.read_excel("matplotlib_data001.xlsx") #创建dataframe对象
df = df[df['信息'] > 0]
danxuan = ['1','2','3','4','5','6','7','8','9','10']
duoxuan = ['11','12','13','14']
fz = {"单选":2 , "多选":3, "15":5 , "16":6, "17":7}
dif = [] #平均分
for i in df.columns[3:]: #枚举每一道题目 i = 1,2,3,4
if i in danxuan:
key = '单选'
elif i in duoxuan:
key = '多选'
else:
key = i
dif.append( round( df[i].mean() , 4) )
dic = {"题号":df.columns[3:] , "难度系数" : dif }
df1 = pd.DataFrame(dic)
#df1.to_excel("难度系数.xlsx")
df1 = df1.sort_values("难度系数")
plt.rcParams["font.sans-serif"] = ["SimHei"] #使用中文
plt.figure(figsize = (8,4))
plt.title("难度最大的10道题对比图")
plt.bar(df1.题号[:10] , df1.难度系数[:10])
plt.xlabel("题号")
plt.ylabel("难度系数")
plt.show()
—— 本文来自火龙信奥(义乌睿码科技):义乌青少年信息学奥赛与编程教育平台,专注 CSP-J/S、NOIP、GESP 竞赛培训,线上线下融合教学,助力编程升学。网址:hlcoding.com