Home > Back-end >  how can i find percentage of the combination of the columns in pandas
how can i find percentage of the combination of the columns in pandas

Time:01-19

I have following dataframe : enter image description here

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.

  • Related