Home > Backend Development > Python Tutorial > How to visualize excel data processing in python

How to visualize excel data processing in python

coldplay.xixi
Release: 2020-10-22 10:22:56
Original
15233 people have browsed it

How to visualize excel data processing in python: first install the xlrd and xlwt libraries to read tables; then use pyecharts to generate the Echarts chart class library; finally install Echarts to read and display Excel data.

How to visualize excel data processing in python

How to visualize excel data processing in python:

Excel table operation

Python mainly uses the two libraries xlrd and xlwt to operate excel, that is, xlrd is a library for reading excel, and xlwt is a library for writing excel.

How to visualize excel data processing in python

Install xlrd

pip install xlrd

Simple table reading

import xlrd
#读取表格
data=xlrd.open_workbook("table.xlsx")
#获取表格的sheets
table=data.sheets()[0]
#输出行数量
print(table.nrows)#8
#输出列数量
print(table.ncols)#4
#获取第一行数据
row1data=table.row_values(0)
print(row1data)#['列1', '列2', '列3', '列4']
print(row1data[0])#列1
Copy after login

Data visualization

pyecharts is a class library for generating Echarts charts. Echarts is a data visualization JS library open sourced by Baidu. The graph visualization effect generated by Echarts is very good. In order to connect with Python, it is convenient to directly use data to generate graphs in Python

Installation

pip install pyecharts

Read Excel Data and display

How to visualize excel data processing in python

import xlrd
from pyecharts.charts import Bar
#读取表格
data=xlrd.open_workbook("table.xlsx")
#获取表格的sheets
table=data.sheets()[0]
#输出行数量
print(table.nrows)
#输出列数量
print(table.ncols)
#获取第一行数据
row1data=table.row_values(0)
print(row1data)#['列1', '列2', '列3', '列4']
print(row1data[0])#列1
xdata=[]
ydata=[]
for i in range(1,table.nrows):
    print(table.row_values(i))
    xdata.append(table.row_values(i)[0])
    ydata.append(table.row_values(i)[1])
print(xdata)
print(ydata)
#数据可视化,柱状图
bar=Bar()
bar.add_xaxis(xdata)
bar.add_yaxis("名称1",ydata)
bar.render("show.html")
Copy after login

Related free learning recommendations: python video tutorial

The above is the detailed content of How to visualize excel data processing in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template