I would like to find a python script to field calculate one field based on another field's value. For example, "Field B" will have a code '23' if "Field A" is equal to CST, or if it is equal to AFF, it will be '11'. Also need to know what to use as a wildcard if CST or AFF is followed by more descriptions.
Solved! Go to Solution.
It will require a code block which is nothing but a python function. Please refer Calculate Field Examples
So all you need is something like
def cal( valA):
if(valA.startswith('CST') or valA.startswith('AFF')):
return 11
else:
return
and call it as
cal(!Field_A!)
Hope that helps.
It will require a code block which is nothing but a python function. Please refer Calculate Field Examples
So all you need is something like
def cal( valA):
if(valA.startswith('CST') or valA.startswith('AFF')):
return 11
else:
return
and call it as
cal(!Field_A!)
Hope that helps.
Thank you very much!
Susan O’Connell
Geographic Information Systems
GIS Specialist
Hi Susan O'Connell,
If your the solution provided by Mahtab Alam solved your problem (and I think it did), could you please mark his answer as the correct one.
Thank you,
Xander
GeoNet Moderator
Hi Susan O'Connell,
I think you ment to mark the answer by Mahtab Alam as helpful, right? Since you marked your own response as helpful.