[SciPy-user] Masked arrays with dtype=object: elements get wrapped in 0D arrays

Vincent Nijs v-nijs at kellogg.northwestern.edu
Tue Jan 9 12:27:11 CST 2007


Jouni,

If you think your code might be generally useful (i.e., apply to any csv
file) would you mind posting it? I put a simple class for reading, writing,
manipulating, and plotting time-series data from/to csv files at
http://scipy.org/Cookbook/dbase

However, it does not work for files with strings (except dates) or missing
values. I'd really like to see how you do that.

Thanks,

Vincent





On 1/9/07 12:12 PM, "Jouni K. Seppänen" <jks at iki.fi> wrote:

> Pierre GM <pgmdevlist at gmail.com> writes:
> 
>> In the meanwhile: what are you trying to do ? There should be some kind of
>> workaround.
> 
> I have a csv file containing strings, floating-point numbers,
> integers, and empty cells (denoting missing data; this is why I want
> to use masked arrays). I read it using the standard csv module, which
> always returns just strings. I convert the result into a masked array
> with dtype=object and iterate through the array, casting anything that
> looks like an int or a float into the appropriate data type, and
> setting the mask at the locations where the value is the empty string.
> Each column in the file is supposed to contain values of just one
> type, so I tried to check this, and was surprised to find that each
> number is of type numpy.ndarray.
> 
> I suppose the simplest workaround is to fix the types and masks in the
> lists returned by csv.reader before making the data into an array.




More information about the SciPy-user mailing list