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

相关内容

热门资讯

推荐攻略!德州透视插件(辅助挂... 推荐攻略!德州透视插件(辅助挂)确实是真的有挂(有挂细节辅助app)1、用户打开应用后不用登录就可以...
揭秘一下!hhpoker脚本(... 揭秘一下!hhpoker脚本(辅助挂)本来真的是有挂(有挂技巧辅助器)1、破解器简单,机器人操作,插...
必看攻略!德普之星透视辅助(辅... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
让我来分享经验!hhpkoer... 让我来分享经验!hhpkoer辅助器视频(辅助挂)都是存在有挂(有挂解惑辅助方法)1、进入到是否有挂...
推荐十款!wepoker私人局... 推荐十款!wepoker私人局透视教程(辅助挂)一直是有挂(有挂规律辅助攻略)进入游戏-大厅左侧-新...
一分钟了解!hhpoker辅助... 一分钟了解!hhpoker辅助器视频(辅助挂)一直有挂(有挂助手辅助方法)小薇(辅助器软件下载)致您...
科技介绍!wepoker透视底... 科技介绍!wepoker透视底牌脚本(辅助挂)果然真的有挂(了解有挂辅助方法)1、实时透视辅助更新:...
重大推荐!cloudpoker... 重大推荐!cloudpoker外挂(辅助挂)其实有挂(有挂详细辅助教程)1、操作简单,无需手机版透视...
大家学习交流!佛手在线大菠萝为... 大家学习交流!佛手在线大菠萝为什么都输(辅助挂)一直真的有挂(有挂技术辅助教程)1、这是跨平台的轻量...
玩家交流!wepoker买脚本... 玩家交流!wepoker买脚本靠谱吗(辅助挂)果然存在有挂(有挂分享辅助脚本)1、该软件可以轻松地帮...