[Numpy-discussion] query to array

Keith Goodman kwgoodman@gmail....
Wed Jan 31 17:00:12 CST 2007


On 1/31/07, BBands <bbands@gmail.com> wrote:
> import pyodbc
> import numpy as np
>
> connection = pyodbc.connect('DSN=DSNname')
> cursor = connection.cursor()
> symbol = 'ibm'
> request = "select to_days(Date), Close from price where symbol = '" +
> symbol + "' and date > '2006-01-01'"
> for row in cursor.execute(request):
>     price.append([row[0], row[1]])
>     priceArray = np.array(price)
>
> Is there a better way to do this? Can fromiter be used?

Why not just pull it all at once with cursor.fetchall()? Then use
np.asarray on the result.


More information about the Numpy-discussion mailing list