import csv
list=[]
with open('tttpsi.csv', encoding='utf-8') as file:
f_csv = csv.reader(file)
for i, rows in enumerate(f_csv):
if i >= 1:
# new_row = []
row = rows[1:-1]
# print(row)
row.sort(reverse=True) #reverse=True 降序排序 默认是升序排序
row_1=row[0:5] #取前五个数值,如果想全部保留,则去掉[0:5]
# print(row_1)
list.append(row_1)
print(list)
with open('mescpsisort.csv', 'w', encoding='utf8', newline='') as f2:
f_csv2 = csv.writer(f2)
f_csv2.writerows(list)
网友评论