Python ';不理解数据类型';定义numpy记录数据类型时出错

Python ';不理解数据类型';定义numpy记录数据类型时出错,python,django,numpy,Python,Django,Numpy,我试图创建一个numpy记录数组来从游标加载数据 当我定义此记录的数据类型时,我收到一个错误“数据类型未理解” 从我所看到的例子来看,我不清楚我在这里做错了什么 python代码: @login_required def resource(request, resource_id): cnxn = pyodbc.connect(SOLAR_SECURED_CONNECTION) cursor = cnxn.cursor() sqlstr = """select r.na

我试图创建一个numpy记录数组来从游标加载数据

当我定义此记录的数据类型时,我收到一个错误“数据类型未理解”

从我所看到的例子来看,我不清楚我在这里做错了什么

python代码:

@login_required
def resource(request, resource_id):
    cnxn = pyodbc.connect(SOLAR_SECURED_CONNECTION)
    cursor = cnxn.cursor()

    sqlstr = """select r.name as resource_name, rm.mobile_id_id, fd.value, pd.update_time, rt.capacity
                    from asset_monitor_resource r, asset_monitor_formulateddata fd, asset_monitor_resourcetype rt,
                         asset_monitor_parseddata pd, asset_monitor_resourcemapping rm
                    where r.id = rm.resource_id_id and
                          r.id = fd.resource_id_id and
                          fd.rawdata_id_Id = pd.rawdata_id_id and
                          r.resource_type_id_id = rt.id and
                          r.id = ?
                    order by pd.update_time desc"""

    cursor.execute(sqlstr, resource_id)

    data_type = np.dtype([('resource_name', np.str, 100),
                          ('mobile_id_id', np.int),
                          ('value', np.float),
                          ('update_time', np.datetime_data),
                          ('capacity', np.int)])

    narray = np.fromiter(cursor.fetchall(), count=-1,
                         dtype=data_type)

    r_rows = cursor.fetchall()

    dateplot(narray, resource_id)
    image_file = "tempfig"+str(resource_id)+".png"

    return render_to_response('resource.html', {'data': r_rows, 'resource_id': resource_id, 'image_file': image_file}, context_instance=RequestContext(request))
回溯

[Tue Dec 03 08:17:24 2013] [error] Internal Server Error: /user/resource/97/
[Tue Dec 03 08:17:24 2013] [error] Traceback (most recent call last):
[Tue Dec 03 08:17:24 2013] [error]   File "C:\\Python27\\Lib\\site-packages\\django\\core\\handlers\\base.py", line 115, in get_response
[Tue Dec 03 08:17:24 2013] [error]     response = callback(request, *callback_args, **callback_kwargs)
[Tue Dec 03 08:17:24 2013] [error]   File "C:\\Python27\\Lib\\site-packages\\django\\contrib\\auth\\decorators.py", line 25, in _wrapped_view
[Tue Dec 03 08:17:24 2013] [error]     return view_func(request, *args, **kwargs)
[Tue Dec 03 08:17:24 2013] [error]   File "C:\\dev\\solar_secured\\asset_monitor\\views.py", line 310, in resource
[Tue Dec 03 08:17:24 2013] [error]     ('capacity', np.int)])
[Tue Dec 03 08:17:24 2013] [error] TypeError: data type not understood

没有数据类型
np.datetime\u data
,它是一个函数:

datetime\u数据(数据类型)

使用适当的数据类型,
np.datetime64
,例如:

>>> np.dtype([('resource_name', np.str, 100),
...           ('mobile_id_id', np.int),
...           ('value', np.float),
...           ('update_time', np.datetime64),
...           ('capacity', np.int)])
dtype([('resource_name', 'S100'), ('mobile_id_id', '<i8'), ('value', '<f8'), ('update_time', '<M8'), ('capacity', '<i8')])
>>np.dtype([('resource_name',np.str,100),
…('mobile_id_id',np.int),
…(“值”,np.浮点),
…('update_time',np.datetime64),
…('capacity',np.int)])

数据类型([('resource_name','S100'),(‘mobile_id_id’,‘如果你不使用容量,它能工作吗?’只使用其他四个数据部分?因为很奇怪,它在那里给出了一个错误,而不是在mobile_id_id的np.int上。在这种情况下,它显示了与更新时间线相同的错误。在我看来,它与整个语句相关,尽管它只显示1 li如果去掉datetime部分?因为正如alko指出的那样,这似乎不是一种合适的数据格式
>>> np.dtype([('resource_name', np.str, 100),
...           ('mobile_id_id', np.int),
...           ('value', np.float),
...           ('update_time', np.datetime64),
...           ('capacity', np.int)])
dtype([('resource_name', 'S100'), ('mobile_id_id', '<i8'), ('value', '<f8'), ('update_time', '<M8'), ('capacity', '<i8')])