按照成绩分组(分数上下浮动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分之间的学生被分到了一组,落在

相关内容

热门资讯

透视讲义!wejoker辅助器... 透视讲义!wejoker辅助器要钱玩吗(WPK方法)竟然存在有辅助脚本(哔哩哔哩)1、wejoker...
透视经验!hhpkoer辅助挂... 透视经验!hhpkoer辅助挂是真的吗(德普之星透视)其实真的是有辅助方法(哔哩哔哩)在进入hhpk...
透视大纲!pokemmo辅助脚... 透视大纲!pokemmo辅助脚本(透视)哈糖大菠萝怎么开挂(辅助)竟然有方法(哔哩哔哩)1)哈糖大菠...
透视手筋!pokemmo手机版... 透视手筋!pokemmo手机版脚本(透视)大菠萝789辅助器下载(辅助)总是是有神器(哔哩哔哩)1)...
透视资料!约局吧德州真的有透视... 透视资料!约局吧德州真的有透视挂吗(透视)智星菠萝透视(辅助)都是真的是有app(哔哩哔哩)1、很好...
透视方式!xpoker辅助控制... 透视方式!xpoker辅助控制(WePoKer简单)真是真的有辅助软件(哔哩哔哩)1、每一步都需要思...
透视法门!wepoker轻量版... 透视法门!wepoker轻量版有透视吗(WPK安卓)果然是有辅助技巧(哔哩哔哩)1、让任何用户在无需...
透视练习!大菠萝辅助器(透视)... 透视练习!大菠萝辅助器(透视)拱趴游戏破解器(辅助)一贯有神器(哔哩哔哩)1)拱趴游戏破解器有没有挂...
透视绝活!poker mast... 透视绝活!poker master辅助(透视)菠萝德州透视脚本(辅助)确实一直都是有工具(哔哩哔哩)...
透视练习!wpk德州局怎么透视... 透视练习!wpk德州局怎么透视(德普之星私人局)其实真的是有辅助脚本(哔哩哔哩)1、该软件可以轻松地...