# Field calculator to update a field using another field in attribute table

1901
11
10-09-2017 09:41 AM
New Contributor III

Hi,

I have the following attribute table. I need to update the fields using the field calculator (SEC, TOWN, RANG) by using the "mtrs" and "label" columns(fields) in the attribute table.

SEC: (letter S + label)   TOWN: (string from mtrs)    RANGE (string from mtrs)      S_R_T (join the SEC+TOWN+RANG)

S24                               T1N                                     R14W                                      S24-T1N-R14W

S4                                 T1N                                     R14W                                      S24-T1N-R14W

S34                               T2S                                     R8W                                        S34-T2S-R8W

.

.

Can somebody help me to achieve this using the "Field Calculator" and Python parser functions?

1 Solution

Accepted Solutions
MVP Legendary Contributor

ahhh... slicing again

``````x = 'abcdefghi__13E'  # ---- since you didn't include an example ----

"R{}{}".format(int(x[11:13]), x[13])  # x = !mtrs!

'R13E'‍‍‍‍‍``````
11 Replies
MVP Legendary Contributor
``"{}-{}-{}".format(!A!, !B!, !C!)‍``

just replace A, B and C with your field names but keep the ! ! marks around them.

Obviously , this has to go into a text field and you have to specify python as the o\parserf

MVP Legendary Contributor

table is hard to read, but I suspect that you are also having trouble with the other bits, like getting the SEC field which would be

``````sectn = '024'

"S{}".format(int(sectn))  # in field calculator  !sectn! with python parser‍‍‍``````

or are those ok... it isn't clear whether you need the whole process completed, just some bits, or all the work?  And how much python do you know?

New Contributor III

Thanks Dan. Yes I figured and it worked. I am a beginner to Python.

MVP Legendary Contributor

Did you find an alternate solution or do you want to close the thread?

New Contributor III

MVP Legendary Contributor

Yes... what have you tried and what should it look like?

This type of functionality is simply python string slicing

other functions string functions

New Contributor III

I used

"R{}".format(int(!mtrs![11:13])) but I am not able to get the East "E" or "W" letter attached like R1E or R18W.

MVP Legendary Contributor

ahhh... slicing again

``````x = 'abcdefghi__13E'  # ---- since you didn't include an example ----

"R{}{}".format(int(x[11:13]), x[13])  # x = !mtrs!

'R13E'‍‍‍‍‍``````
New Contributor III

You are genius. I got the trick now. Thanks a bunch.