Here is a code for automatic scoring once you get students' answer sheet and standard answer sheet.
| Problem |
1 |
2 |
3 |
4 |
| Alice |
A |
BD |
D |
C |
| Bob |
B |
CD |
D |
C |
| David |
B |
AB |
A |
C |
| Mike |
B |
AC |
C |
D |
| Problem |
1 |
2 |
3 |
4 |
| Answer |
A |
BD |
D |
C |
| Score |
1 |
2 |
1 |
1 |
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import openpyxl
#input two dataframe, stdt_ans is students' answer sheet dataframe (row: Name, column: problem),
#and corr_ans is the standard answer dataframe (1st row: standard answer for each problem, 2nd row, score for each prolem)
def Get_scores(stdt_ans,corr_ans):
Score_matrix = stdt_ans.copy()
row_num = len(stdt_ans) #row number, i.e. student number
col_num = len(stdt_ans.columns)#col number, i.e. problem number
for m in range(row_num): #iterate by row
for n in range(1,col_num): #iterate by column
if stdt_ans.iat[m,n] == corr_ans.iat[0,n]: #if same as std ans, get score
Score_matrix.iat[m,n] = float(corr_ans.iat[1,n])
else: #otherwise no score
Score_matrix.iat[m,n] = 0
Score_matrix['Sum'] = Score_matrix.iloc[:,1:col_num].sum(axis = 1) #get total score of each student
Score_matrix = Score_matrix.sort_values(by=['Sum'], ascending = False)#sort by total score
print(Score_matrix)
df3 = Score_matrix.drop(columns = ['Name'], axis = 1)
df3 = df3.astype('float')
result = df3.describe(include = 'all' ) #get average scores for each problem
print(result)
Score_matrix.to_excel('Score_results.xlsx')
result.to_excel('Analysis.xlsx')
fig = Score_matrix['Sum'].plot(kind ='hist') #plot histogram
fig.set_xlabel("Total scores")
fig.set_ylabel("Counts")
plt.savefig('sum_hist.pdf')
return
#an example
df1 = pd.read_excel("ans.xlsx")
df2 = pd.read_excel("standard.xlsx")
Get_scores(df1,df2)