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

相关内容

热门资讯

记者揭秘!创思维激k透视挂,雀... 记者揭秘!创思维激k透视挂,雀友会辅助潮汕麻将脚本,详细工具(有挂方法)1、首先打开雀友会辅助潮汕麻...
黑科技技巧!wepoker有脚... 黑科技技巧!wepoker有脚本吗,红龙poker辅助,果然是真的有挂(有挂方式)一、红龙poker...
一分钟快速了解!微信小程序微乐... 一分钟快速了解!微信小程序微乐辅助器教程,微乐家乡官方app下载,详细工具(有挂总结)1)微信小程序...
黑科技辅助挂!wepoker私... 黑科技辅助挂!wepoker私局辅助,德普之星有透视辅助吗,都是真的是有挂(有挂讲解)1、完成德普之...
一分钟快速了解!财神十三张脚本... 一分钟快速了解!财神十三张脚本辅助,小松宿松游戏辅助,详细教程(有挂详情)所有人都在同一条线上,像星...
软件辅助挂!wejoker辅助... 软件辅助挂!wejoker辅助软件,德普之星辅助软件,都是真的有挂(有挂技巧)1、每一步都需要思考,...
必备攻略!微乐陕西小程序破解器... 必备攻略!微乐陕西小程序破解器下载,微信小程序游戏破解微乐游戏,详细教程(有挂分析)1、该软件可以轻...
突发!哈糖大菠萝软件下载,德普... 突发!哈糖大菠萝软件下载,德普之星辅助器,切实存在有挂(有挂详细)1、操作简单,无需德普之星辅助器手...
科普攻略!超凡辅助软件,518... 科普攻略!超凡辅助软件,518互游辅助器下载,详细挂(了解有挂)1、这是跨平台的518互游辅助器下载...
无独有偶!wepoker怎么拿... 无独有偶!wepoker怎么拿到好牌,德普之星透视,本来是真的有挂(有挂分享)1、德普之星透视模拟器...