I have an attribute field that has a description that I only want to display a specific string or text. I'm not sure if using a rsearch or rfind or another method for displaying what I want is best? For example, the text field:
FIVE OAKS CROSSING ADDN BLOCK 1 LOT 6 PER PLAT D214124070 |
SUMMER CREEK SOUTH ADDITION BLOCK 8 LOT 3 |
I am only wanting to pull out the Block and block number and Lot and Lot number
thanks for any advice
Solved! Go to Solution.
Jeremy you might want to mark mine correct.
Now for the ones with the spaces, you will have to modify indx0 for those cases
for example...
idx0 = row.index('BL OCK')
>>> import re
...
... strings = [
... "VILLAGES OF WOODLAND SPRINGS BLOCK 44 LOT 4",
... "FIVE OAKS CROSSING ADDN BLOCK 1 LOT 6 PER PLAT D214124070",
... "SUMMER CREEK SOUTH ADDITION BLOCK 8 LOT 3"
... ]
...
>>>
>>> for s in strings:
... print(re.findall('(BLOCK|LOT) (\S*) ?',s))
...
[('BLOCK', '44'), ('LOT', '4')]
[('BLOCK', '1'), ('LOT', '6')]
[('BLOCK', '8'), ('LOT', '3')]
>>>
A fake field and a function to try with the field calculator, python parser,
code block is below.
expression line
do_stuff(!YourFieldNameHere!)
lines 14-16 simulate a fake column 'a'
hopefully you get the drift. I wrote it as overtly as possible
a = [ 'VILLAGES OF WOODLAND SPRINGS BLOCK 44 LOT 4',
'FIVE OAKS CROSSING ADDN BLOCK 1 LOT 6 PER PLAT D214124070',
'SUMMER CREEK SOUTH ADDITION BLOCK 8 LOT 3']
def do_stuff(a_val):
"""call using do_stuff(!Your_fld!)"""
row = a_val.split(" ")
idx0 = row.index('BLOCK')
idx1 = row.index('LOT')
out = " ".join(row[idx1:idx1+2] + row[idx0:idx0+2])
return out
for a_val in a:
returned = do_stuff(a_val)
print(returned)
LOT 4 BLOCK 44
LOT 6 BLOCK 1
LOT 3 BLOCK 8
My example that I used actually has lots and lots of blocks and lots with numbers, what could I use to grab them all?
show an example.
Is the stuff in a table (see the field calculator example I posted) or what format are they in?
add a new text field and try the field calculator code block and expression I posted. python parser code block as above and the expression would be
do_stuff(!legaldesc!)
Can I see how you put this in? I can't get mine to work. I am also doing this in ArgGIS Pro, not sure if that will make a difference
legaldesc is the attribute field that I am looking to do this on
for the visual types...
I swapped the code block up so block appears before lot (my bad in the original)