First, data:
| Name |
Air quality |
Degree of contamination |
Other |
Score |
| Shanghai |
44.5 |
8.151949 |
14.46154 |
67.11349 |
| Beijing |
34 |
8.095238 |
15.15873 |
57.25397 |
| Guangzhou |
33 |
10.23364 |
13.27103 |
56.50467 |
| Chengdu |
38.5 |
10.2129 |
15.94406 |
64.65695 |
| Wuhan |
42.5 |
13.26796 |
18.52273 |
74.29069 |
| Nanjing |
50 |
7.461452 |
14.63576 |
72.09721 |
| Chongqing |
50 |
11.16099 |
15.21127 |
76.37226 |
| Nanchang |
48.5 |
12.3913 |
17.82609 |
78.71739 |
| Guiyang |
49.5 |
30 |
20 |
99.5 |
Second, the processing script:
#!/usr/bin/env python3# -*- coding: utf-8 -*-"uses Python to sort the data. # date 2016-11-10 ' import xlrddef read_execl_ranking (filename,worktable= ' Sheet1 '): #对数据排序, optimized version. workbook = xlrd.open_workbook (FileName) sheet_name = workbook.sheet_names () [1] sheet = workbook.sheet_by_index (1) sheet = workbook.sheet_by_name (worktable) print ("Various rankings! ") print ('-' *20) for j in range (1, Sheet.ncols): lie = {} print (Sheet.cell (0,j) value+ ":") for i in range (1,sheet.nrows): lie[sheet.celL (i,0). Value] = sheet.cell (I,J) .value i = i+1 newlie = sorted ( Lie.items (), key = lambda d:d[1],reverse = true) for i in range (0,len (Newlie)): print (newlie[i][0]+ ":" +str (newlie[i][1]) + "points," ,end = ' ') i = i+1 print ("") if __name__ == "__main__": Filename=r ' execl_test.xlsx ' read_execl_ranking (filename=filename,worktable= ' Sheet4 ')
Third, the result diagram:
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/8A/03/wKioL1gkIz_CWay5AAF02BLklvM497.jpg-wh_500x0-wm_3 -wmp_4-s_1876603471.jpg "title=" 3.jpg "alt=" Wkiol1gkiz_cway5aaf02blklvm497.jpg-wh_50 "/>
This article is from the "Urban Cloth" blog, please be sure to keep this source http://sunday208.blog.51cto.com/377871/1871491
Python3 implement Excel to sort the reading data