AttributeError:“ time.struct_time”对象没有属性“ toordinal”

Ste*_*min 5 python matplotlib

我是python新手,我无法理解如何正确格式化日期。

我的数据是这样的 Fri, 09 Dec 2011 06:50:37 UTC

我正在这样准备:

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

然后我正在尝试使用它

dates = matplotlib.dates.date2num(dates)
Run Code Online (Sandbox Code Playgroud)

得到以下错误:

AttributeError: 'time.struct_time' object has no attribute 'toordinal'
Run Code Online (Sandbox Code Playgroud)

Ble*_*der 5

您正在使用time模块,但是matplotlib需要该datetime对象。

尝试使用如下所示的内容:

from datetime import datetime

dates.append(datetime.strptime(row[5], "%a, %d %b %Y %H:%M:%S %Z"))
...
Run Code Online (Sandbox Code Playgroud)