Python 将混合数据类型的MySQLdb数据加载到Numpy';桑达雷

Python 将混合数据类型的MySQLdb数据加载到Numpy';桑达雷,python,mysql,sql,numpy,Python,Mysql,Sql,Numpy,我有一个mySQL数据,看起来像这样(SequelPro的输出),表名为 mytable: 该SQL db的总体结构如下所示: 我要做的是将上面的表加载到numpy 2d数组中。 这是我的代码: import MySQLdb as mdb import numpy as np db = conn.connect(host = "somehost.ac.jp", user = "gandalf", passwd = "abc

我有一个mySQL数据,看起来像这样(SequelPro的输出),表名为
mytable

该SQL db的总体结构如下所示:

我要做的是将上面的表加载到numpy 2d数组中。 这是我的代码:

import MySQLdb as mdb
import numpy as np

db = conn.connect(host = "somehost.ac.jp",
                 user = "gandalf",
                 passwd = "abcxxx",
                 db = "mygreatdb",
                 )
cursor = conn.cursor()
sql = """
      SELECT * from %s
      """ %mdb.escape_string(tablename)
cursor.execute(sql)
results = cursor.fetchall()
num_rows = int(cursor.rowcount)



D = np.fromiter(results, count=num_rows, dtype=('c8,str,f,f,f,f,f,f'))
print D
但是,它给出了以下错误:

    D = np.fromiter(results, count=num_rows, dtype=('c8,str,f,f,f,f,f,f'))
TypeError: a float is required
正确的方法是什么?对我来说,主要的问题似乎是我不确定 如何正确构造
dtype
。SQLs(
char,mediumtext,float
)的numpy等价物是什么?请告知

最后,我想得到如下所示的np.array:

array([['101D','NONRBP', 2.829e-07,....,0.00030],
       ['115L','NONRBP', 2.5e-5,....,0.01772]])

我想,问题在于其中一个跳蚤列中的NULL。在传递到fromiter之前,您需要将空值转换为浮点值。