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

相关内容

热门资讯

WPK软件!AApoker神器... WPK软件!AApoker神器开挂ai,德扑软件,原来存在有ai开挂秘籍1、下载好德扑软件正确养号方...
WPK脚本!红龙扑克技巧辅助器... WPK脚本!红龙扑克技巧辅助器ai,aapoker脚本怎么用,原来是有ai辅助器方针1、首先打开aa...
WPK脚本!德州扑克app透视... WPK脚本!德州扑克app透视挂ai,aapoker辅助工具安全吗,果然有ai透视挂烘培aapoke...
WPK透视!菠萝智星德州app... WPK透视!菠萝智星德州app透视挂ai,werplan脚本,果然存在有ai透视挂教材该软件可以轻松...
WPK真假!菠萝智星德州教程开... WPK真假!菠萝智星德州教程开挂ai,wpk插件,切实存在有ai开挂要领WPK真假!菠萝智星德州教程...
WPK四人!德州扑克工具辅助a... WPK四人!德州扑克工具辅助ai,德州机器人代打脚本,总是存在有ai辅助方针WPK四人!德州扑克工具...
WPK透视!WePoKer技巧... WPK透视!WePoKer技巧开挂ai,哈糖大菠萝万能挂,都是是真的有ai开挂妙招1、玩家可以在哈糖...
WPK安卓!AApoker插件... WPK安卓!AApoker插件辅助ai,poker world辅助,本来是真的有ai辅助妙计1、进入...
WPK工具!WPK神器开挂ai... WPK工具!WPK神器开挂ai,德扑之星怎么作弊,真是是有ai开挂讲义1、很好的工具软件,可以解锁游...
WPK多开!微扑克方法辅助ai... WPK多开!微扑克方法辅助ai,约局吧app有挂吗,果然真的是有ai辅助演示约局吧app有挂吗辅助器...