Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'time.struct_time' object has no attribute 'toordinal'

I'm novice in python, and I couldn't understand how to correctly formatting dates.

My data is like this Fri, 09 Dec 2011 06:50:37 UTC

I'm preparing it like this:

dates.append(time.strptime(row[5], "%a, %d %b %Y %H:%M:%S %Z"))

Then I'm trying to use it

dates = matplotlib.dates.date2num(dates)

get following error:

AttributeError: 'time.struct_time' object has no attribute 'toordinal'
like image 432
Stepan Kuzmin Avatar asked Dec 16 '11 18:12

Stepan Kuzmin


1 Answers

You are using the time module, but matplotlib expects the datetime object.

Try using something like this:

from datetime import datetime

dates.append(datetime.strptime(row[5], "%a, %d %b %Y %H:%M:%S %Z"))
...
like image 154
Blender Avatar answered Oct 16 '22 01:10

Blender