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

相关内容

热门资讯

三分钟了解!填大坑辅助器攻略,... 三分钟了解!填大坑辅助器攻略,同乡游辅助工具,详细神器(有挂规律)1、许多玩家不知道填大坑辅助器攻略...
2026版软件!wepoker... 2026版软件!wepoker免费脚本弱密码,德普之星辅助器,确实确实有挂(有挂工具)1、该软件可以...
总算了解!乐酷副厅辅助,闲逸辅... 总算了解!乐酷副厅辅助,闲逸辅助器下载,详细软件(有挂透视)1、总算了解!乐酷副厅辅助,闲逸辅助器下...
网友热议!wepoker辅助器... 网友热议!wepoker辅助器免费,德扑之心免费透视,确实是真的有挂(有挂透明挂)网友热议!wepo...
实测交流!广东雀神挂件脚本开挂... 实测交流!广东雀神挂件脚本开挂,新畅游辅助器,详细教程(有挂工具)广东雀神挂件脚本开挂是不是有人用挂...
今天下午!fishpoker透... 今天下午!fishpoker透视底牌,德普之星辅助器app,果然存在有挂(存在有挂)德普之星辅助器a...
重大消息!来几局辅助器开挂,链... 重大消息!来几局辅助器开挂,链接大厅辅助插件有哪些,详细脚本(有挂方法)1、该软件可以轻松地帮助玩家...
黑科技辅助!hh poker软... 黑科技辅助!hh poker软件,德普辅助软件,一直真的是有挂(有挂方式)1、上手简单,内置详细流程...
终于清楚!吉祥填大坑辅助器攻略... 终于清楚!吉祥填大坑辅助器攻略,博乐填大坑有没有buff,详细挂(有挂教程)亲,关键说明,吉祥填大坑...
据报道!wepoker插件功能... 据报道!wepoker插件功能辅助器,德普之星私人局辅助器,原来真的是有挂(新版有挂)1、实时德普之...