[Numpy-discussion] loading database data into numpy arrays

Keith Goodman kwgoodman@gmail....
Thu Aug 19 12:18:29 CDT 2010

On Thu, Aug 19, 2010 at 10:00 AM, John Salvatier
<jsalvati@u.washington.edu> wrote:
> Hello,
> I am trying to load some time series data into numpy arrays from a MySQL
> database using pyodbc, but I am not sure what the standard way to do this
> is. I found the following:
> http://www.aidanfindlater.com/python-db-api-to-numpy but when I tried after
> doing a select (I made sure the cursor had rows).
> np.fromiter(cursor, dtype=[('a',float), ('b', float)])
> I got
> Traceback (most recent call last):
>   File "<console>", line 1, in <module>
>   File "C:\Users\jsalvatier\workspace\rpxdata\src\rpxdata\mysql.py", line
> 45, in run_statistics_15
>     return np.fromiter(cursor, dtype=[('a',float), ('b', float)])
> TypeError: expected a readable buffer object
> Does anyone have advice on this?

How about np.asarray(cursor.fetchall())?

More information about the NumPy-Discussion mailing list