The operation and Python Excel data visualization

Excel table operations

python operation excel mainly used xlrd and xlwt two libraries that xlrd read excel, xlwt write excel library.

Installation xlrd

pip install xlrd

Read simple form

Import to xlrd 

# read table 
Data = xlrd.open_workbook ( " table.xlsx " ) 

# acquired form sheets 
Table = data.sheets () [0] 

# output line number of 
print (table.nrows) # . 8 

# output columns Number of 
print (table.ncols) # . 4 

# acquiring first data row 
row1data = table.row_values (0)
 Print (row1data) # [ 'column 1', 'column 2', 'column 3' 'column. 4'] 
Print (row1data [0]) # column 1

data visualization

pyecharts library is used to generate a graph Echarts. Echarts Baidu is a open source data visualization JS library. FIG Echarts generated by visualization great, to interface with Python, easy to use data generated directly in Python FIG.

installation

pip install pyecharts

Read Excel data and display

Import to xlrd
 from pyecharts.charts Import Bar 

# read table 
Data = xlrd.open_workbook ( " table.xlsx " ) 

# acquired form sheets 
Table = data.sheets () [0] 

# output line number 
Print (table.nrows) 

# number of output column 
Print (table.ncols) 

# acquiring a first data row 
row1data = table.row_values (0)
 Print (row1data) # [ 'column 1', 'column 2', 'column 3' 'column. 4'] 
Print (row1data [0]) # column. 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")

 

Guess you like

Origin www.cnblogs.com/dongxiaodong/p/12238172.html