[Numpy-discussion] Numpy Array of dtype=object with strings and floats question

Darryl Wallace darryl.wallace@prosensus...
Tue Nov 10 14:57:22 CST 2009


Hello!

On Tue, Nov 10, 2009 at 2:23 PM, Pierre GM <pgmdevlist@gmail.com> wrote:

>
> On Nov 10, 2009, at 1:09 PM, Darryl Wallace wrote:
>
> > Hello again,
> >
> > The best way so far that's come to my attention is to use:
> >
> > numpy.ma.masked_object
>
> Will only work for masking one specific string, as you've noticed.
> >
> > Can anyone help me so that all strings are found in the array without
> having to explicitly loop through them in Python?
>
> This looks like it's working:
> >>> mask = (mixed >= '')
> >>> mixed = ma.array(np.where(~mask,mixed,np.nan),mask=mask,dtype=float)
>

This method worked the best and fastest.
Thanks for your help on this one :)

>
> > On Fri, Nov 6, 2009 at 3:56 PM, Darryl Wallace <
> darryl.wallace@prosensus.ca> wrote:
> > What I'm doing is importing some data from excel and sometimes there are
> strings in the worksheet.
>
> Now, what are you using to read the Excel file ? Do you get a list that you
> transform into an array, or an ndarray straightaway ?


It depends, I will use Excel if it's available otherwise I will use XLRD.
 Using win32com, excel returns a tuple of tuples from the range that is
selected.  XLRD returns a list of lists.  To keep things consistent I return
a numpy array straight away.

darryl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20091110/6277adae/attachment.html 


More information about the NumPy-Discussion mailing list