-3

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

ap306
  • 205
  • 1
  • 2
  • 8

1 Answers1

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)
inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241