在下面,我可以从SQL获取行和列数据:
如何将表头作为结果集或数组的一部分.?
top = csr.execute("Select * from bigtop")
d=list(top)
a = np.asarray(d, dtype='object')
print a
Run Code Online (Sandbox Code Playgroud)
就像我在这里问的那样: 如何在Python中用数据库创建CSV文件?
如果您希望列名称作为数组中的第一行,您可以这样做
top = csr.execute("Select * from bigtop")
d=list(top)
a = np.asarray([[x[0] for x in top.description]] + d, dtype='object')
Run Code Online (Sandbox Code Playgroud)
并得到类似的东西
array([[heading1, heading2, heading3, ...],
[val1, val2, val3, ...],
...
, dtype=object)
Run Code Online (Sandbox Code Playgroud)