Good Morning All,
I've been tasked with populating a unit (Text Field) attribute in a specific data set. All units in this data are currently blank, BUT inside of the Unit Description field, there is a unit number, that in 99 % of the cases, follows the word "UNIT". So my question is this. Is it possible to create a python script to find the word "UNIT" in the Unit description field, Then populate the Unit field with all characters that follow that word? Thank you in advance for your responses and help
-MD-
Solved! Go to Solution.
many ways, this is but one
fld ="I am UNIT 99A b c" # -- a sample field entry
(fld.rpartition("UNIT")[-1]).strip() # -- python parser of course
'99A b c' # -- result
This partitions a text string based on a separator. [-1] takes the last bit of the partition. strip() just removes any leading or trailing spaces.
replace fld in the above with your fieldname enclosed in exclamation marks
eg !UnitDescription!
many ways, this is but one
fld ="I am UNIT 99A b c" # -- a sample field entry
(fld.rpartition("UNIT")[-1]).strip() # -- python parser of course
'99A b c' # -- result
This partitions a text string based on a separator. [-1] takes the last bit of the partition. strip() just removes any leading or trailing spaces.
replace fld in the above with your fieldname enclosed in exclamation marks
eg !UnitDescription!