Select to view content in your preferred language

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

2844
11
Jump to solution
10-09-2017 09:41 AM
DuminduJayasekera
Regular Contributor

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 Emeritus

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 Emeritus
"{}-{}-{}".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 Emeritus

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
Regular Contributor

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

0 Kudos
DanPatterson_Retired
MVP Emeritus

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

0 Kudos
DuminduJayasekera
Regular Contributor

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 Emeritus

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
Regular Contributor

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 Emeritus

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
Regular Contributor

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

0 Kudos