import openpyxl as xl
wb = xl.load_workbook("豆瓣TOP250电影.xlsx")
ws = wb[wb.sheetnames[0]]
newList = []
for i in range(2, 252):
everyList = []
everyList.append(ws["B" + str(i)].value)
everyList.append(ws["A" + str(i)].value)
everyList.append(ws["C" + str(i)].value)
newList.append(everyList)
newList.sort()
newList.reverse()
wb = xl.Workbook()
ws = wb.active
ws["A1"] = "电影名称"
ws["B1"] = "评分"
ws["C1"] = "资料"
for i in range(2, 252):
ws["A" + str(i)] = newList[i-2][1]
ws["B" + str(i)] = newList[i-2][0]
ws["C" + str(i)] = newList[i-2][2]
wb.save("按评分排名.xlsx")
我是这么做的...而且有种鱼老师要掏出两行代码秒杀我的感觉XD |