I keep getting errors that it does not append when trying to do this.
Solved! Go to Solution.
Yes. If it can't convert the string into a number, the conversion will fail. You need to strip out the character:
# NewField =
convert(!OldField!)
# Code Block
def convert(x):
try:
x = x.replace('"', '')
return float(x)
except:
return None
You can't update the field type if there is data in the field.
Perhaps you can elaborate on what you are trying to do for alternate suggestions
i know that. the only work around was to create another field with the desired data type and fill it, however that is not working
Or if you don't want to use a code block... (substitute !junk! for your field name of course)
float(!junk!) if !junk!.isnumeric() else None
Create a new Double field, then run Calculate Field with this Python expression (note the exclamation marks in line 2):
# NewField =
convert(!OldField!)
# Code Block
def convert(x):
try:
return float(x)
except:
return None
These sound great. My specific issue is related to pipe diameter. So they have the " inch sign attached to the numbers, and that may be why it is not going into the double field?
Yes. If it can't convert the string into a number, the conversion will fail. You need to strip out the character:
# NewField =
convert(!OldField!)
# Code Block
def convert(x):
try:
x = x.replace('"', '')
return float(x)
except:
return None
Awesome, that seemed to do the trick, thanks!