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

Advertisements

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.

>Solution :

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.

Leave a ReplyCancel reply