CodePudding user response:
Try using .groupby(['week', 'classes'])['attendence'].agg(['sum', 'count']) on your dataframe to get both the numbers of rows and the number of attendences grouped by week and class. Then divide sum by count to get the percentages. You can use pivot to get classes in the columns.