Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading