# -*- coding:utf-8 -*-
"""
作者:秦舞阳
日期:2022年5月20日
"""
import xlrd
import xlwt
import numpy as np
import matplotlib.pyplot as plt
#显示中文
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False
rows = 0
a = list(range(0,37))
b = list(range(0,37))
c = list(range(0,37))
d = list(range(0,37))
e = list(range(0,37))
excel_1 = xlrd.open_workbook(r"20电气2班花名册.xlsx")
sheet_1 = excel_1.sheet_by_index(0)
excel_2 = xlwt.Workbook(encoding='utf-8')
# name= input("请输入你的学号后两位:")
#遍历取值
for row in range(sheet_1.nrows):
a[row]= sheet_1.cell(row, 2).value
b=a[row]
c[row]=b[0]
print(c)
#字典计数
count_dict = dict()
for item in c:
if item in count_dict:
count_dict[item] += 1
else:
count_dict[item] = 1
print(count_dict)
del count_dict['姓']
#取出字典的值
for d in count_dict.values():
d= count_dict.values()
print(d)
#取出字典的键
for e in sorted(count_dict.keys()):
e= count_dict.keys()
print(e)
#根据字典的键值作图
plt.figure(figsize=(38,5))
plt.bar(e,d,color = 'green',width = 0.3)
plt.xlabel('姓氏')
plt.ylabel('人数')
plt.show()