AttributeError:'time.struct_time'对象没有' toordinal '属性
我刚接触Python,对如何正确格式化日期有点困惑。
我的数据是这样的 Fri, 09 Dec 2011 06:50:37 UTC
我准备数据的方式是这样的:
dates.append(time.strptime(row[5], "%a, %d %b %Y %H:%M:%S %Z"))
然后我尝试使用它
dates = matplotlib.dates.date2num(dates)
结果出现了以下错误:
AttributeError: 'time.struct_time' object has no attribute 'toordinal'
1 个回答
5
你正在使用time
模块,但matplotlib
需要的是datetime
对象。
可以试试下面这样的写法:
from datetime import datetime
dates.append(datetime.strptime(row[5], "%a, %d %b %Y %H:%M:%S %Z"))
...