how can i find percentage of the combination of the columns in pandas

Question:

I have following dataframe :
enter link description here for dataframe

I want output like this. according to week and classes. In the base of attendence where 1 count percentage of the classes & week.

enter image description here

Asked By: Dipam Soni

||

Answers:

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.

Answered By: TiemvdDeure