copying values from string type column to double column

170
4
Jump to solution
12-08-2021 04:46 AM
klabine
New Contributor

Essentially I am trying to get xy coordinates from a CSV. I have already converted the CSV to DBase and added 2 new double fields for LAT and LONG. But the original latitude and longitude values are in string type fields and contain "NA" values for some of the coordinates. I can remove the NA fields using a cursor because they are useless for plotting xy coordinates but I still am unable to copy the coordinate data from the string type columns to the new double type columns. 

klabine_0-1638963776754.png

I have also tried the 2 following cursors as well

klabine_1-1638963858106.png

and regardless of what I do I receive the following error:

ExecuteError: ERROR 999999: Error executing function.
The value type is incompatible with the field type. [LAT]

 

0 Kudos
1 Solution

Accepted Solutions
DonMorrison1
Occasional Contributor III

Have you tried to explicitly convert the string to a double before writing it? For instance in your 2nd example:

row[1] = float(row[0])

 

View solution in original post

0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

Code formatting ... the Community Version - Esri Community

lat = "45.0"

float(lat)
45.0

You have to "float" text representations of numbers


... sort of retired...
0 Kudos
DonMorrison1
Occasional Contributor III

Have you tried to explicitly convert the string to a double before writing it? For instance in your 2nd example:

row[1] = float(row[0])

 

0 Kudos
klabine
New Contributor

I realize now that some of my data is incorrectly inputted (see below) and therefor I get this error : "ValueError: invalid literal for float(): 3.745.562.167". I can easily remove the incorrect data now, but the code will actually be used by people without gis experience and unfortunately these error will probably occur in future data. Is there a way to delete these error value rows within my cursor? 

(still new to python, thanks for your help!)

klabine_0-1639031769880.png

 

0 Kudos
klabine
New Contributor

Once I remove the weirdly formatted lat and long values it wont work using float but will work without so I have just done the following:

klabine_0-1639036308587.png

Thanks for your help!

0 Kudos