按照成绩分组(分数上下浮动5分)
创始人
2024-08-23 14:00:27
0

可以使用Python中的pandas库实现此任务。以下是可以使用的示例代码:

import pandas as pd

# 创建包含学生成绩的DataFrame
grades = pd.DataFrame({
    'name': ['Alice', 'Bob', 'Charlie', 'David', 'Emma', 'Frank', 'Grace', 'Henry', 'Isabel', 'Jack'],
    'score': [72, 78, 80, 85, 87, 90, 92, 95, 96, 98]
})

# 将分数四舍五入到最接近的5的倍数
grades['rounded_score'] = round(grades['score'] / 5) * 5

# 根据分数分组
grouped = grades.groupby('rounded_score')

# 打印每个组中的人员
for name, group in grouped:
    print(name)
    print(group)

输出为:

70.0
      name  score  rounded_score
0    Alice     72           70.0
80.0
      name  score  rounded_score
1      Bob     78           80.0
2  Charlie     80           80.0
85.0
    name  score  rounded_score
3  David     85           85.0
87.0
   name  score  rounded_score
4  Emma     87           85.0
90.0
     name  score  rounded_score
5   Frank     90           90.0
92.0
    name  score  rounded_score
6  Grace     92           90.0
95.0
    name  score  rounded_score
7  Henry     95           95.0
96.0
     name  score  rounded_score
8  Isabel     96           95.0
98.0
   name  score  rounded_score
9  Jack     98           98.0

可以看到,成绩落在70分到80分之间的学生被分到了一组,落在

相关内容

热门资讯

透视游戏!wepoker免费钻... 透视游戏!wepoker免费钻石,wepoker私人局辅助器怎么用(详细靠谱)1、进入游戏-大厅左侧...
透视系统!aapoker怎么控... 透视系统!aapoker怎么控制牌(透视)aapoker辅助器是真的吗,2025新版技巧(有挂细节)...
透视好友!wepoker有什么... 透视好友!wepoker有什么规律,wepoker俱乐部辅助(详细透视挂底牌)wepoker俱乐部辅...
透视苹果版!aapoker怎么... 透视苹果版!aapoker怎么设置提高好牌几率(透视)aapoker怎么选牌,透明教程(有挂黑科技)...
透视模拟器!wepoker软件... 透视模拟器!wepoker软件辅助程序,wepoker私局辅助(详细有有挂规律)1、透视模拟器!we...
透视攻略!aapoker能控制... 透视攻略!aapoker能控制牌吗(透视)aapoker辅助软件合法吗,黑科技教程(有挂辅助)1、透...
透视挂透视!wepoker可以... 透视挂透视!wepoker可以免费玩吗,wepoker作弊视频(详细有人用过)1、wepoker可以...
透视存在!aapoker脚本怎... 透视存在!aapoker脚本怎么用(透视)aapoker如何设置胜率,安装教程(有挂脚本);1、上手...
透视脚本!poker辅助器免费... 透视脚本!poker辅助器免费安装,黑侠破解wepoker(详细辅助软件视频)1、构建自己的poke...
透视实锤!aapoker怎么拿... 透视实锤!aapoker怎么拿好牌(透视)aapoker ai插件,线上教程(有挂揭秘)1、上手简单...