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

Darryl Wallace darryl.wallace at prosensus.ca
Tue Nov 10 15:57:22 EST 2009


Hello!

On Tue, Nov 10, 2009 at 2:23 PM, Pierre GM <pgmdevlist at 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 at 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.python.org/pipermail/numpy-discussion/attachments/20091110/6277adae/attachment.html>


More information about the NumPy-Discussion mailing list