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

I am new to python and I could not figure out how to format dates correctly.

My details are similar to Fri, 09 Dec 2011 06:50:37 UTC

I prepare it like this:

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

Then i try to use it

 dates = matplotlib.dates.date2num(dates) 

get the following error:

 AttributeError: 'time.struct_time' object has no attribute 'toordinal' 
+3
source share
1 answer

You are using the time module, but matplotlib expecting a 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")) ... 
+4
source

Source: https://habr.com/ru/post/971081/


All Articles