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

相关内容

热门资讯

分享开挂内幕!九九联盟辅助,奇... 分享开挂内幕!九九联盟辅助,奇迹手游辅助(总是是真的有挂)奇迹手游辅助辅助器是一种具有地方特色的麻将...
分享认知!小唐家乐园辅助器,w... 分享认知!小唐家乐园辅助器,we poker插件,大神讲解(有挂讲解);1、这是跨平台的小唐家乐园辅...
必备攻略!欢乐达人暗堡破解,光... 必备攻略!欢乐达人暗堡破解,光明大厅微信链接辅助试用(果然是真的有挂)1)光明大厅微信链接辅助试用有...
总算了解!小逸碰胡辅助器,德州... 总算了解!小逸碰胡辅助器,德州私人局脚本,细节揭秘(有挂功能);人气非常高,ai更新快且高清可以动的...
一起来探讨!科乐填大坑作弊码,... 一起来探讨!科乐填大坑作弊码,老友广东潮汕麻雀(果然真的有挂)1.老友广东潮汕麻雀 选牌创建新账号,...
新手必备!威信茶馆大贰破解,u... 新手必备!威信茶馆大贰破解,uupoker透视,总结教程(今日头条);相信小伙伴都知道这个威信茶馆大...
揭秘攻略!闲来透视辅助器最新版... 揭秘攻略!闲来透视辅助器最新版,欢乐联盟免费辅助(好像是真的有挂)1、完成闲来透视辅助器最新版有辅助...
一分钟揭秘!金虎爷有挂吗,we... 一分钟揭秘!金虎爷有挂吗,we-poker正规吗,曝光教程(有挂猫腻);1、点击下载安装,金虎爷有挂...
三分钟了解!内蒙博乐填大坑辅助... 三分钟了解!内蒙博乐填大坑辅助,雀神广东定制插件辅助(确实是有挂)在进入雀神广东定制插件辅助软件靠谱...
总算清楚!潮汕雀友会辅助,we... 【福星临门,好运相随】;总算清楚!潮汕雀友会辅助,wepoker开辅助能查到吗,微扑克教程(有挂解密...