按照成绩分组(分数上下浮动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、下载好德普之星透视辅助软件透...
一分钟指南!智星德州插件202... 一分钟指南!智星德州插件2024最新版(透视)好像存在有辅助脚本(哔哩哔哩)1、全新机制【智星德州插...
第1分钟攻略!约局吧如何查看是... 第1分钟攻略!约局吧如何查看是否有挂(透视)原来存在有辅助下载(哔哩哔哩)约局吧如何查看是否有挂辅助...
第七分钟学习!hhpoker辅... 第七分钟学习!hhpoker辅助软件(透视)本来真的是有辅助插件(哔哩哔哩)1、hhpoker辅助软...
四分钟总结!hhpoker免费... 四分钟总结!hhpoker免费辅助器(透视)真是真的是有辅助下载(哔哩哔哩)1.hhpoker免费辅...
第二分钟手册!wepoker辅... 第二分钟手册!wepoker辅助器(透视)其实是真的有辅助教程(哔哩哔哩)1、完成wepoker辅助...
4分钟窍要!wepoker透视... 4分钟窍要!wepoker透视功能下载(透视)果然有辅助神器(哔哩哔哩)1、全新机制【wepoker...
三分钟妙计!wepoker私人... 三分钟妙计!wepoker私人局有透视吗(透视)一直真的有辅助工具(哔哩哔哩)1、三分钟妙计!wep...
七分钟方针!拱趴大菠萝自动计算... 七分钟方针!拱趴大菠萝自动计算机器人(透视)原来存在有辅助辅助(哔哩哔哩)1、完成拱趴大菠萝自动计算...
第7分钟大纲!we-poker... 第7分钟大纲!we-poker软件(透视)竟然真的有辅助辅助(哔哩哔哩)该软件可以轻松地帮助玩家将w...