栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

班级姓氏柱状图统计

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

班级姓氏柱状图统计

# -*- 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()
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/935018.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号