Thanks for the help,<div><br></div><div>I'll test out this simple example.<br><br><div class="gmail_quote">On Tue, Nov 10, 2009 at 2:28 PM, Keith Goodman <span dir="ltr"><<a href="mailto:kwgoodman@gmail.com">kwgoodman@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">On Tue, Nov 10, 2009 at 11:14 AM, Keith Goodman <<a href="mailto:kwgoodman@gmail.com">kwgoodman@gmail.com</a>> wrote:<br>

> On Tue, Nov 10, 2009 at 10:53 AM, Darryl Wallace<br>
<div class="im">> <<a href="mailto:darryl.wallace@prosensus.ca">darryl.wallace@prosensus.ca</a>> wrote:<br>
</div><div class="im">>> I currently do as you suggested.  But when the dataset size becomes large,<br>
>> it gets to be quite slow due to the overhead of python looping.<br>
><br>
</div>> Are you using a for loop? Is so, something like this might be faster:<br>
><br>
>>> x = [1, 2, '', 3, 4, 'String']<br>
>>> from numpy import nan<br>
>>> [(z, nan)[type(z) is str] for z in x]<br>
>   [1, 2, nan, 3, 4, nan]<br>
><br>
> I use something similar in my code, so I'm interested to see if anyone<br>
> can speed things up using python or numpy, or both. I run it on each<br>
> row of the file replacing '' with None. Here's the benchmark code:<br>
><br>
>>> x = [1, 2, '', 4, 5, '', 7, 8, 9, 10]<br>
>>> timeit [(z, None)[z is ''] for z in x]<br>
> 100000 loops, best of 3: 2.32 µs per loop<br>
<br>
If there are few missing values (my use case), this seems to be faster:<br>
<br>
def myfunc(x):<br>
    while '' in x:<br>
        x[x.index('')] = None<br>
    return x<br>
<br>
>> timeit myfunc(x)<br>
1000000 loops, best of 3: 697 ns per loop<br>
<br>
Note that it works inplace.<br>
<div><div></div><div class="h5">_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>______________________________________<br>Darryl Wallace: Project Leader<br>ProSensus Inc.<br>McMaster Innovation Park<br>175 Longwood Road South, Suite 301<br>
Hamilton, Ontario, L8P 0A1<br>Canada        (GMT -05:00) <br><br>Tel:       1-905-528-9136<br>Fax:       1-905-546-1372<br><br>Web site:  <a href="http://www.prosensus.ca/">http://www.prosensus.ca/</a><br>______________________________________<br>

</div>