I want to sort a CSV table by date. Started out being a simple task:
import sys import csv reader = csv.reader(open("files.csv"), delimiter=";") for id, path, title, date, author, platform, type, port in reader: print date
I used Python's CSV module to read in a file with that structure:
id;file;description;date;author;platform;type;port
The optimal solution would be to have a CSV client that handles the file like a database. I didn't find anything like that.
I hope somebody knows some nice sorting magic here ;)
import operator sortedlist = sorted(reader, key=operator.itemgetter(3), reverse=True)
or use lambda
sortedlist = sorted(reader, key=lambda row: row[3], reverse=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With