I have DF like this:
and I want to calculate how much is students was prepared via his overall score in the exam, like this:
How can I do it?
Edit: the answer given by @user17242583 is right, but, the values are stacked in the first rows, how to implement each value to each needed row ?
CodePudding user response:
You probably want something like this:
s = df.groupby(['Student', 'Exam']).apply(lambda group: (f'{group["IsCorrect"].sum()}\\{group.shape[0]}', (group['IsCorrect'].sum() / group.shape[0]))).reset_index(drop=True)
df['prepared'] = s.str[0]
df['prepared percentage'] = s.str[1]