Issue
I'm trying to read a CSV file using numpy.recfromcsv(...)
where some of the fields have commas in them. The fields that have commas in them are surrounded by quotes i.e., "value1, value2"
. Numpy see's the quoted field as two different fields and it doesn't work very well. The command I'm using right now is
data = numpy.recfromcsv(dataFilename, delimiter=',', autstrip=True)
I found this question
But it doesn't use numpy
, which I'd really love to use.
So I'm hoping there are at least one of a few options here:
- What are some options to
numpy.recfromcsv(...)
that will allow me to read a quoted field as one field instead of multiple comma separated fields? - Should I format my CSV file differently?
- (alternatively, but not ideally) Read CSV as in quoted question, with extra steps to create
numpy
array.
Please advise.
Solution
It turns out the easiest way to do this is to use the standard library module, csv
to read in the file into a tuple, then use the tuple as input to a numpy array. I wish I could just read it in with numpy, but that doesn't seem to work.
Answered By - jlconlin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.