按照成绩分组(分数上下浮动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、这是跨...
专业讨论!微乐自建房辅助工具神... 专业讨论!微乐自建房辅助工具神器,微乐小程序免费黑科技(开挂自建房)脚本1、微乐自建房辅助工具神器模...
大家学习交流!微乐家乡麻将自建... 大家学习交流!微乐家乡麻将自建房辅助app,微乐家乡麻将自建房辅助app(开挂自建房)教程1、该软件...
记者揭秘!微信雀神麻将挂件开挂... 记者揭秘!微信雀神麻将挂件开挂辅助,微乐家乡麻将自建房辅助app(开挂自建房)app1、每一步都需要...
我来分享!微乐自建房辅助工具脚... 我来分享!微乐自建房辅助工具脚本,微乐自建房脚本免费入口(开挂自建房)脚本1、下载好微乐自建房辅助工...
玩家实测!微乐微信自建房辅助工... 玩家实测!微乐微信自建房辅助工具插件,微乐小程序免费黑科技(开挂自建房)软件1、微乐微信自建房辅助工...
终于懂了!微乐自建房辅助工具脚... 终于懂了!微乐自建房辅助工具脚本,微乐自建房脚本免费入口(开挂自建房)攻略1.微乐自建房辅助工具脚本...
重大通报!微乐家乡麻将自建房辅... 重大通报!微乐家乡麻将自建房辅助app,微乐自建房脚本免费入口(开挂自建房)攻略微乐家乡麻将自建房辅...
盘点一款!微乐自建房辅助工具挂... 盘点一款!微乐自建房辅助工具挂,微乐家乡麻将自建房辅助app(开挂自建房)技巧运微乐家乡麻将自建房辅...
今日公布!微乐自建房辅助工具挂... 今日公布!微乐自建房辅助工具挂,微乐小程序免费黑科技(开挂自建房)工具1、起透看视 微乐自建房辅助工...