Starting with anwser of this:
Using Numpy to create Yahoo finance price table
import numpy as np
import pylab as pl
import urllib
url = "http://ichart.yahoo.com/table.csv?a=2&c=2011&b=30&e=7&d=7&g=d&f=2011&s=msft&ignore=.csv"
f = urllib.urlopen(url)
title = f.readline().strip().split(",")
data = np.loadtxt(f, dtype=np.float, delimiter=",", converters={0: pl.datestr2num})
I would like to insert return rows into db. data looks like below:
[[734233.0 25.98 26.31 25.86 26.15 65581400 25.98]
[734232.0 25.82 26.18 25.74 25.78 73694500 25.61]
[734231.0 25.45 25.66 25.41 25.55 35433700 25.38]
[734228.0 25.53 25.53 25.31 25.48 63114200 25.31]
[734227.0 25.60 25.68 25.34 25.39 63233700 25.22]
[734226.0 25.60 25.72 25.50 25.61 41999300 25.44]]
How would I parse this numpy array to a list or table so I can insert into database. Notice that all row are not separated, but rather one line. The db part works.
data.tolist() does not parse single rows
looking for output like
[[734233.0 ,25.98 ,26.31 ,25.86 ,26.15, 65581400, 25.98]
[734232.0, 25.82, 26.18, 25.74, 25.78, 73694500, 25.61]
[734231.0, 25.45 ,25.66, 25.41, 25.55, 35433700, 25.38]
[734228.0, 25.53, 25.53, 25.31, 25.48, 63114200, 25.31]
[734227.0, 25.60 ,25.68, 25.34, 25.39, 63233700, 25.22]
[734226.0, 25.60, 25.72, 25.50, 25.61, 41999300, 25.44]]
Would replace " " with "," work?
numpy.ndarray
of the right number of dimensions. – Chinmay Kanchi Aug 12 '11 at 16:38