第4栏有出生日期(年/月/日)。我希望这个专栏按递增顺序排序;然后输出到文件。
请协助
答案 0 :(得分: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)