2014-02-26 47 views

回答

0
import csv 
from datetime import datetime 
with open('path/to/file') as infile, open('path/to/output', 'w') as outfile: 
    rows = [line for line in csv.reader(infile)] 
    rows.sort(key=lambda row:datetime.strptime(row[3], "%d/%m/%Y")) 
    writer = csv.writer(outfile) 
    writer.writerows(rows) 
+0

的格式謝謝,但第5行lamda是什麼? – ap306

+0

@ ap306:該lambda將第4列轉換爲機器可解析的日期/時間,用於排序 – inspectorG4dget

相關問題