发布时间:2019-09-26 07:27:17编辑:auto阅读(1800)
一、数据:
名称 | 空气质量 | 污染程度 | 其他 | 得分 |
上海 | 44.5 | 8.151949 | 14.46154 | 67.11349 |
北京 | 34 | 8.095238 | 15.15873 | 57.25397 |
广州 | 33 | 10.23364 | 13.27103 | 56.50467 |
成都 | 38.5 | 10.2129 | 15.94406 | 64.65695 |
武汉 | 42.5 | 13.26796 | 18.52273 | 74.29069 |
南京 | 50 | 7.461452 | 14.63576 | 72.09721 |
重庆 | 50 | 11.16099 | 15.21127 | 76.37226 |
南昌 | 48.5 | 12.3913 | 17.82609 | 78.71739 |
贵阳 | 49.5 | 30 | 20 | 99.5 |
二、处理脚本:
#!/usr/bin/env python3 # -*- coding: utf-8 -*- ''' 使用python对数据排序。 # date 2016-11-10 ''' import xlrd def Read_execl_ranking(FileName,WorkTable='Sheet1'): #对数据排序,优化版本。 workbook = xlrd.open_workbook(FileName) sheet_name = workbook.sheet_names()[1] sheet = workbook.sheet_by_index(1) sheet = workbook.sheet_by_name(WorkTable) print ("各项排名!") 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])+"分," ,end = ' ') i = i+1 print ("") if __name__ == "__main__": FileName=r'execl_test.xlsx' Read_execl_ranking(FileName=FileName,WorkTable='Sheet4')
三、结果图:
上一篇: 如何使用python3抓取微信公众号文章
下一篇: Python3代码工程化加密
47754
46259
37140
34647
29238
25896
24766
19870
19433
17924
5724°
6329°
5845°
5897°
6998°
5835°
5854°
6368°
6323°
7688°