我有一个mySQL数据,看起来像这样(SequelPro的输出),表名为
mytable
:
SQL数据库的总体结构如下所示:
我要做的是将上面的表加载到numpy2d数组中。 这是我的代码:
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
但是它给出了以下错误:
^{pr2}$正确的方法是什么?对我来说主要的问题似乎是我不确定
如何正确构造dtype
。SQLs(char, mediumtext, float
)的numpy等价物是什么?请告知。在
最后我想得到np.数组看起来像这样:
array([['101D','NONRBP', 2.829e-07,....,0.00030],
['115L','NONRBP', 2.5e-5,....,0.01772]])
目前没有回答
相关问题 更多 >
编程相关推荐