I have this csv file which look like this:
datetime_period,value
01 Apr 2021 00:00,92.85
01 Apr 2021 00:30,91.73
11 Feb 2021 19:30,88.58
11 Feb 2021 20:00,88.58
13 Jan 2021 13:00,80.49
13 Jan 2021 13:30,81.95
I want to sort this csv according to the datetime in column datetime_period
.
I used this link Sorting a csv object by dates in python as a guide.
Here is my code;
data = csv.reader(open(csv_file_path, 'r'))
data = sorted(data, key=lambda row: datetime.strptime(row[0], "%d %b %Y %H:%M"))
I get the error:
ValueError: time data 'time_period' does not match format '%d %b %Y %H:%M'
python-BaseException
I looked at the code and think my code does match the datetime
format.
Can someone tell me what is wrong with the code or provide an alternative solution?
I am using python 3.8.5