I have a small python script that generates a csv output that looks like this:
Username, Timestamp
User1, 2012-11-06 14:08:26
User1, 2012-11-06 14:08:02
This list can be in the range of hundreds of rows, so I’m looking to put a short script together that would simply print out the oldest and most recent timestamp date (or the smallest value) of column B. It seems in principle fairly easy, but as these are dates, I’ve not been able yet to apply some code that makes it work. I tried to apply a solution similar to what I find here, but I could’t get it to work:
How to extract column and row in csv using python
import csv
def main():
reader = csv.reader(open('file.csv'), "rb"), delimiter=',')
headerline = reader.next()
data = [(int(row[1]), row['']) for row in csv.DictReader(reader)]
data.sort()
print data[0]
I’m not entirely fluent in python, so I probably am just not seeing the mistake, so any help would be greatly appreciated!
Sample code: