前言

最近学习数据分析,感觉Python做数据分析真的好用。
PDF转换为Excel,可以用这个网址转化:
https://www.ilovepdf.com/zh-cn/pdf_to_excel

正文

安装Pycharts

conda install xlrd
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyecharts

一、准备数据

1、载入Excel 表格

# coding=utf8
import xlrd
import numpy as np
from pyecharts.charts import Bar
from pyecharts.charts import Pie, Grid
from pyecharts import options as opts# ==================== 准备数据 ====================
# 导入Excel 文件
data = xlrd.open_workbook("机电学院2020年硕士研究生复试拟录取结果公示.xlsx")
# 载入第一个表格
table = data.sheets()[0]

2、提取Excel 表格数据

tables = []def Read_Excel(excel):# 从第2行开始读取数据,因为这个Excel文件里面从第四行开始才是考生信息for rows in range(1, excel.nrows - 1):dict_ = {"id": "", "name": "", "status": "", "preliminary_score": "", "retest_score": "", "total_score": "","ranking": ""}dict_["id"] = table.cell_value(rows, 0)dict_["name"] = table.cell_value(rows, 1)dict_["status"] = table.cell_value(rows, 8)dict_["remarks"] = table.cell_value(rows, 3)dict_["preliminary_score"] = table.cell_value(rows, 5)dict_["retest_score"] = table.cell_value(rows, 6)dict_["total_score"] = table.cell_value(rows, 7)dict_["ranking"] = table.cell_value(rows, 10)# 将未被录取或者非普通计划录取的考生滤除if dict_["status"] == str("是") and dict_["remarks"] == str("全日制"):tables.append(dict_)

打印数据:

# 执行上面方法
Read_Excel(table)
for i in tables:print(i)

3、数据分段统计
根据自己的需求进行修改

num_score_300_310 = 0
num_score_310_320 = 0
num_score_320_330 = 0
num_score_330_340 = 0
num_score_340_350 = 0
num_score_350_360 = 0
num_score_360_370 = 0
num_score_370_380 = 0
num_score_380_390 = 0
num_score_390_400 = 0
num_score_400_410 = 0
min_score = 999
max_score = 0# 将各个分段的数量统计
for i in tables:score = i["preliminary_score"]if score > max_score:max_score = scoreif score < min_score:min_score = scoreif score in range(300, 310):num_score_300_310 = num_score_300_310 + 1elif score in range(310, 320):num_score_310_320 = num_score_310_320 + 1elif score in range(320, 330):num_score_320_330 = num_score_320_330 + 1elif score in range(330, 340):num_score_330_340 = num_score_330_340 + 1elif score in range(340, 350):num_score_340_350 = num_score_340_350 + 1elif score in range(350, 360):num_score_350_360 = num_score_350_360 + 1elif score in range(360, 370):num_score_360_370 = num_score_360_370 + 1elif score in range(370, 380):num_score_370_380 = num_score_370_380 + 1elif score in range(380, 390):num_score_380_390 = num_score_380_390 + 1elif score in range(390, 400):num_score_390_400 = num_score_390_400 + 1elif score in range(400, 410):num_score_400_410 = num_score_400_410 + 1# 构建两个元组用以后期建表方便
bar_x_axis_data = ("300-310", "310-320", "320-330", "330-340", "340-350", "350-360", "360-370", "370-380", "380-390", "390-400", "400-410")
bar_y_axis_data = (num_score_300_310, num_score_310_320, num_score_320_330,num_score_330_340, num_score_340_350, num_score_350_360,num_score_360_370, num_score_370_380, num_score_380_390,num_score_390_400, num_score_400_410)

4、绘制可视化图形
有网站可以参考:https://pyecharts.org/#/zh-cn/intro
绘制柱状图:

# ===================== 柱状图 =====================
# 构建柱状图
c = (Bar().add_xaxis(bar_x_axis_data).add_yaxis("录取考生", bar_y_axis_data, color="#af00ff").set_global_opts(title_opts=opts.TitleOpts(title="数量")).render("./录取数据图.html")
)

绘制饼状图:

# ====================== 饼图 ======================
c = (Pie(init_opts=opts.InitOpts(height="800px", width="1200px")).add("录取分数概览",[list(z) for z in zip(bar_x_axis_data, bar_y_axis_data)],center=["35%", "38%"],radius="40%",label_opts=opts.LabelOpts(formatter="{b|{b}: }{c}  {per|{d}%}  ",rich={"b": {"fontSize": 16, "lineHeight": 33},"per": {"color": "#eee","backgroundColor": "#334455","padding": [2, 4],"borderRadius": 2,},})).set_global_opts(title_opts=opts.TitleOpts(title="录取", subtitle='Made by rengar'),legend_opts=opts.LegendOpts(pos_left="0%", pos_top="65%")).render("./录取饼图.html")
)

生成了两个html文件,在你当前文件夹下,打开可以看到图



中间可以根据自己需要,再进行修改代码
这个实验的所有代码、数据、结果都在我的码云里保存,下面是链接
https://gitee.com/rengarwang/Excel-visualization

利用Python读取Excel表格并可视化相关推荐

  1. 【Python数据分析】利用Python删除EXCEL表格中指定的列数据或行数据

    如何利用Python删除EXCEL表格中指定的列数据?今天与大家一起分享一下DataFrame对象的drop()函数,drop()函数可根据标签删除EXCEL表格中的列数据或行数据,其语法格式如下: ...

  2. 【Python数据分析】利用Python替换EXCEL表格中指定的数据

    如何利用Python替换EXCEL表格中指定的数据?今天与大家一起分享一下DataFrame对象的replace()函数,replace()函数可EXCEl中的数据内容,其语法格式如下: 表达式.re ...

  3. python读取excel表格-python读取excel表格中的数据

    使用python语言实现Excel 表格中的数据读取,需要用到xlrd.py模块,实现程序如下: import xlrd #导入xlrd模块 class ExcelData(): def __init ...

  4. 利用python处理excel表格

    利用python处理excel表格 注意事项:在excel打开状态下无法进行写入和保存,但是可以读取. 1.excel的两种格式(xlsx,xls) 建议使用xlsx,遇到xls统统都用pandas转 ...

  5. 如何利用python将excel表格中筛选出来的每一份数据各自另存为新的excel文件?

    如何利用python将excel表格中筛选出来的每一份数据各自另存为新的excel文件? 1.问题描述 2.解决过程 2.1 问题分析: 2.2 解决思路 3.运行结果 1.问题描述 最近在处理一堆工 ...

  6. python画柱状图和折线图-Python读取Excel表格,并同时画折线图和柱状图的方法

    今日给大家分享一个Python读取Excel表格,同时采用表格中的数值画图柱状图和折线图,这里只需要几行代码便可以实. 首先我们需要安装一个Excel操作的库xlrd,这个很简单,在安装Python后 ...

  7. python读取excel表格数据

    python操作excel主要用到xlrd和xlwt两个库,xlrd读取表格数据,支持xlsx和xls格式的excel表格:xlwt写入excel表格数据 一.python读取excel表格数据 1. ...

  8. python 显示表格数据_python显示excel表格数据-怎么用python读取excel表格的数据

    怎么用python读取excel表格的数据 #导入包 import xlrd #设置路径 path='C:\\Users\\jyjh\\Desktop\\datap.xlsx' #打开 data=xl ...

  9. python读取Excel表格文件

    python读取Excel表格文件,例如获取这个文件的数据 python读取Excel表格文件,需要如下步骤: 1.安装Excel读取数据的库-----xlrd 直接pip install xlrd安 ...

最新文章

  1. android程序设计期末试题b,《Android程序设计》期末试题B.doc
  2. JS删除数组元素的函数介绍
  3. ie浏览器网页版进入_荟萃浏览器v2.10.2清爽版 网页秒开/装机必备
  4. POJ 3687 逆序拓扑
  5. 全网首发:编译jna:dispatch.h:30:34: fatal error: com_sun_jna_Function.h: 没有那个文件或目录
  6. CCF推荐期刊会议(A类)
  7. CUDA C编程入门
  8. win10打开internet信息服务器,Win10打开internet信息服务的方法
  9. 密码破解---实验八:Windows本地破解用户口令
  10. 陈坤发微博调侃 回应儿子生母话题
  11. pandas-task08-文本数据.md
  12. mysql 连续天数_MYSQL面试题:统计连续打卡天数
  13. 小白学STM32——跑马灯库函数版本
  14. 极客日报:蚂蚁启动春招,技术人才需求超八成;微软动视暴雪收购案遭调查;Firefox 98 发布|极客头条
  15. 2015年高考物理复习重点
  16. 『学了就忘』Linux基础 — UNIX系统介绍
  17. ### 通达信数据之实时机构持股数据接口
  18. 郭明錤:2018年苹果将保留iPhone X镜头设计
  19. Bilibili直播的弹幕数据包解析
  20. 美股量化交易的优势有哪些?

热门文章

  1. 【UVM基础】uvm_agent 中的 is_active 变量释义
  2. photoshop读书笔记
  3. OCR论文阅读笔记01--multi-oriented scence text detection via corner localization and regin segmentation
  4. 二叉树、B树(B-树)、B+树、B*树详解,以及为什么MySQL选择B+树做索引
  5. python截图工具和模拟鼠标键盘_python PyAutoGUI 模拟鼠标键盘操作和截屏功能
  6. 字符串查找工具 批量搜索文件的文本内容工具
  7. YOLOv5-优化器和学习率调整策略
  8. 【数据结构】无向图的遍历(广度搜索和深度搜索)
  9. 关于添加 HKEY_LOCAL_MACHINE32\Software 注册表问题
  10. 读书、学习、工作和生活中收集的20条经典语录:1-20