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?
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]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.