Currently when I import a data file, I create a list, and then use the
method to convert the list into a numpy array.
However, ideally I would like to not have to use a transition data type before converting it to a numpy array (and import the .csv file directly into a numpy array).
I have tried the
method, however, that does not keep the inherent matrix structure I am attempting to preserve (it creates a single vector instead of maintaining the distinct columns and rows from the .csv).
My import method basically looks like this:
When I try to add something like:
However, I am finding that the result is just an empty numpy array at the completion of the loop.
I have also tried
, however it seems to me like the number of columns must be known apriori to use this (and I don't know how to use the
to determine the number of columns.
Any ideas / assistance you could provide would be most greatly appreciated.!!!
Code:
numpy.array(lst)
However, ideally I would like to not have to use a transition data type before converting it to a numpy array (and import the .csv file directly into a numpy array).
I have tried the
Code:
numpy.genfromtext()
My import method basically looks like this:
Code:
import csv f = open('fileName.csv','rb') rdr = csv.reader(f,delimeter=',') lst = [] for row in rdr: lst.append(row)
Code:
numArray = numpy.array([]) for row in rdr: numpy.append(numArray,row)
I have also tried
Code:
numpy.row_stack
Code:
csv.reader()
Any ideas / assistance you could provide would be most greatly appreciated.!!!
Comment