Note that there are some explanatory texts on larger screens.

plurals
  1. POPython - convert string to float (the conventional method, float(), is not working in this case)
    primarykey
    data
    text
    <p>In working with some of our data, I had to perform a pretty basic conditional combinations of columns. After filling null values, attempted to add to columns in the assignment of a new variable. One of the columns ended up being object, which is not at all unprecedented. What I found, however, was that seemingly valid values would not convert to float (e.g. 4,789.67). After much searching, it seems that every solution I have seen points to the existence of an irregular character (which does not describe my case). Consequently, I tried to experiment in IPython to recreate the error, and I was successful. I do not understand, however, why I got this error:</p> <p>TEST</p> <pre><code>z='4,534.07' #initial assignment print z print type(z) #checked type print repr(z) #tried to reveal hidden characters print repr(z.replace("'","")) #tried to remove excess quotes print z[1:-1] #tried again to remove excess quotes print float(z) #failed conversion attempt </code></pre> <p>OUTPUT</p> <pre><code>4,534.07 &lt;type 'str'&gt; '4,534.07' '4,534.07' ,534.0 --------------------------------------------------------------------------- ValueError Traceback (most recent call last) &lt;ipython-input-70-8a3c46ebe6ab&gt; in &lt;module&gt;() 6 print z[1:-1] 7 print z ----&gt; 8 print float(z) ValueError: invalid literal for float(): 4,534.07 </code></pre> <p>The solutions I have seen for the basic conversion question invariably suggest the following for conversion of 'x' to float -->> float(x). I would be very grateful for anyone who can explain what I have missed. (I have not had this happen before.)</p> <p>I have been using the Enthought platform:</p> <hr> <p>Release notes Canopy 1.0.0.1160</p> <p>Canopy 1.0.0</p> <p>First release. See Documention Browser, Canopy Users Guide for release notes describing what's new and any known issues and workarounds</p> <hr> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload