简体   繁体   English

我如何找到 pandas 中列组合的百分比

[英]how can i find percentage of the combination of the columns in pandas

I have following dataframe: enter link description here for dataframe我有以下 dataframe: enter link description here for dataframe

I want output like this.我想要这样的 output。 according to week and classes.根据周和班级。 In the base of attendence where 1 count percentage of the classes & week.在出勤率基础上,1 计算班级和周的百分比。

在此处输入图像描述

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.尝试在您的 dataframe 上使用.groupby(['week', 'classes'])['attendence'].agg(['sum', 'count'])来获取按以下方式分组的行数和出席人数week 和 class。然后用 sum 除以 count 得到百分比。 You can use pivot to get classes in the columns.您可以使用 pivot 获取列中的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM