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

1262
11
Jump to solution
10-09-2017 09:41 AM
DuminduJayasekera
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?

Thanks a lot in advance.

 

1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed 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'

View solution in original post

11 Replies
DanPatterson_Retired
MVP Esteemed 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

DanPatterson_Retired
MVP Esteemed 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?

DuminduJayasekera
New Contributor III

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

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

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

0 Kudos
DuminduJayasekera
New Contributor III

Apologies for the late reply. Your answers were very helpful. Is there a way I can extract RANGE using the "mtrs" column?

0 Kudos
DanPatterson_Retired
MVP Esteemed 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

DuminduJayasekera
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.

0 Kudos
DanPatterson_Retired
MVP Esteemed 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'
DuminduJayasekera
New Contributor III

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

0 Kudos