I'm attempting to add a character to an ID field in ArcPro (eg. 2.14 -> 2.014, 2.15 -> 2.015, etc.). Rather than manually do the couple hundred attributes, I'm sure there is a way to do this with a code block in Field Calculator but I can't seem to figure it out. Does anyone have any tips? Thank you!
Solved! Go to Solution.
Hello Zach,
In theory, you could also just do
!NumberBefore!.replace(".",".0")
This should just replace the period with a period and a zero. You should only have to put that in the top section and not need a Code Block, I think.
Best regards,
Rachel
Esri Support Services
Hello Zach,
Is there a pattern to where you want to place the character? In other words, is it always going after the second character (in the above example the 2 and the period are the first two characters), or is it always going to be after the decimal, etc?
There should be a way to split the string, concatenate it with the desired character, and then re-concatenate the string halves. It'll only work if there's a pattern though.
Thanks!
Rachel
Esri Support Services
Yes, it will always be after the decimal. Basically it's a double ID with the number before the decimal being the group ID and after the decimal being the attribute ID and I'm just trying to add a hundreds place to the attribute ID.
I've done similar things in Desktop but I'm not very experienced with Pro (or python code blocks) and believe I'm just missing some element or having something in the wrong spot.
Thanks for the response!
Hello Zach,
Assuming:
Then the following should work for you in Field Calculator
NewField=
addzero(!NumberBefore!)
Code Block=
def addzero(inputString):
beforePeriod = inputString.split(".")[0]
afterPeriod = inputString.split(".")[1]
concatenateAll = beforePeriod+".0"+afterPeriod
return concatenateAll
Here's a screenshot of the whole thing:
Let me know if that works?
Best regards,
Rachel
Esri Support Services
Hello Zach,
In theory, you could also just do
!NumberBefore!.replace(".",".0")
This should just replace the period with a period and a zero. You should only have to put that in the top section and not need a Code Block, I think.
Best regards,
Rachel
Esri Support Services
That worked!
Thank you Rachel