You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 10 09:38:05 2022
@author: Administrator
"""
import pandas as pd
#从键盘输入一个班级名称
class_name = input ( )
################start###############
#1.从文件‘学生花名册.xls’ 中读取数据,放在一个DataFrame对象df中
df = pd . read_excel ( " 学生花名册.xls " )
#################end################
#基于这个DataFrame对象df完成下面的操作:
################start###############
#2.输出class_name班级前3位同学姓名
df1 = df . groupby ( by = " 班级名称 " ) . get_group ( class_name )
print ( df1 [ " 姓名 " ] . head ( 3 ) )
#################end################
################start###############
#3.统计class_name班级不同性别的学生人数( 用学号列统计)
print ( df1 . groupby ( by = " 性别 " ) [ " 学号 " ] . count ( ) )
#################end################