Hello, I am fairly new to Python and just started working with ArcPro. I have a solution for my problem working in an excel formula but would like to know how to get this to work in Code Block of Pro.
I have 2 fields; Location and Section. My excel formula is this:
=IF((LEFT(A2,3)="RMS"),"",REPLACE(A2,1,1,B2))
A2 is location and B2 is Section. So if the 1st 3 characters of the location = RMS then nothing else replace the first character with Section
The data looks like this
Location | Section | Formula |
B - 18 - F - 1 - N.5 | A | A - 18 - F - 1 - N.5 |
RMS - 18 - F - 1 - N.6 | RMS |
I have been searching all over but just can't seem to figure it out.
Thank you.
Solved! Go to Solution.
def replace_(fld, val):
"""Replace a value if found"""
if fld[:3] == val:
return val
else:
return fld[:3]
python expression
replace_(!Location!, "RMS")
code block is above
However... you really don't say what you want to do it the Location field isn't really RMS ???
Ideally I would like to update the location field and not create a new field. So if location starts with RMS then do nothing but if the 1st character in Location does not equal Section then update the 1st character in location to change to Section value. Hopefully that makes sense. Thank you!
I think I figured it out, thank you for the help.