column 4 has date of birth (dd/mm/yyyy). I would like this column to be sorted in an increasing order; and then output to a file.
Please assist
column 4 has date of birth (dd/mm/yyyy). I would like this column to be sorted in an increasing order; and then output to a file.
Please assist
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)