Creating new field in ArcGIS Desktop which contains values from two different columns with certain...
Suppose I have a attribute table as shown in the image below:

I have columns A and B with common FID. I would like to add a new column C, which contains the values of column A with the condition that if the value is equal to 25 in that column, then for those rows, the value should be assigned from column B.
The highlighted green color column C in the image is how the result should look like.
Is there a tool to do this or does an expression have to be used?
arcgis-desktop attribute-table
add a comment |
Suppose I have a attribute table as shown in the image below:

I have columns A and B with common FID. I would like to add a new column C, which contains the values of column A with the condition that if the value is equal to 25 in that column, then for those rows, the value should be assigned from column B.
The highlighted green color column C in the image is how the result should look like.
Is there a tool to do this or does an expression have to be used?
arcgis-desktop attribute-table
add a comment |
Suppose I have a attribute table as shown in the image below:

I have columns A and B with common FID. I would like to add a new column C, which contains the values of column A with the condition that if the value is equal to 25 in that column, then for those rows, the value should be assigned from column B.
The highlighted green color column C in the image is how the result should look like.
Is there a tool to do this or does an expression have to be used?
arcgis-desktop attribute-table
Suppose I have a attribute table as shown in the image below:

I have columns A and B with common FID. I would like to add a new column C, which contains the values of column A with the condition that if the value is equal to 25 in that column, then for those rows, the value should be assigned from column B.
The highlighted green color column C in the image is how the result should look like.
Is there a tool to do this or does an expression have to be used?
arcgis-desktop attribute-table
arcgis-desktop attribute-table
edited Dec 15 '18 at 3:40
Vince
14.5k32748
14.5k32748
asked Dec 5 '18 at 6:07
nishnish
102
102
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
You can use Field Calculator using Python Parser:

in the Pre-Logic Script write the following code:
def getValue(f1,f2):
if f1 == 25:
return f2
else:
return f1
C=
getValue(!A! , !B!)
add a comment |
Python has ternary conditional operator:
!B! if !A! == 25 else !A!
@nish, to get more information about a shortcut conditional expression, please check this link.
– Taras
Dec 5 '18 at 6:51
1
Simplest the best, no pre-logic script, no argument ordering.
– fatih_dur
Dec 5 '18 at 8:03
add a comment |
You can use Field Calculator (see examples here) or the da.UpdateCursor like below. Change input and field names and execute in the python window of ArcMap.
import arcpy
fc = r'C:data.gdbfeature_class' #Change to match your data
fields = ['A','B','C'] #Change to match your data
with arcpy.da.UpdateCursor(fc,fields) as cursor:
for row in cursor:
if row[0] == 25:
row[2] = row[1]
else:
row[2] = row[0]
cursor.updateRow(row)
1
Thank you. But i wasn't sure where to input this code.
– nish
Dec 5 '18 at 6:43
1
@BERA, have you ever used any GIS with GUI? =)
– Taras
Dec 5 '18 at 7:05
1
@BERA, P.S. as always a perfect answer
– Taras
Dec 5 '18 at 8:14
add a comment |
In the Field Calculator with a usage of Python parser, please type
Pre-Logic Script Code:
def CalcColumn(fieldA, fieldB):
if fieldA == 25:
return fieldB
else:
return fieldA
C =
CalcColumn(!A!, !B!)
References:
- Basic If/Then in Python Parser of ArcGIS Field Calculator?
- Python script for if/elif condition in field calculator
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f305018%2fcreating-new-field-in-arcgis-desktop-which-contains-values-from-two-different-co%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use Field Calculator using Python Parser:

in the Pre-Logic Script write the following code:
def getValue(f1,f2):
if f1 == 25:
return f2
else:
return f1
C=
getValue(!A! , !B!)
add a comment |
You can use Field Calculator using Python Parser:

in the Pre-Logic Script write the following code:
def getValue(f1,f2):
if f1 == 25:
return f2
else:
return f1
C=
getValue(!A! , !B!)
add a comment |
You can use Field Calculator using Python Parser:

in the Pre-Logic Script write the following code:
def getValue(f1,f2):
if f1 == 25:
return f2
else:
return f1
C=
getValue(!A! , !B!)
You can use Field Calculator using Python Parser:

in the Pre-Logic Script write the following code:
def getValue(f1,f2):
if f1 == 25:
return f2
else:
return f1
C=
getValue(!A! , !B!)
answered Dec 5 '18 at 6:23
ahmadhanbahmadhanb
22.3k32052
22.3k32052
add a comment |
add a comment |
Python has ternary conditional operator:
!B! if !A! == 25 else !A!
@nish, to get more information about a shortcut conditional expression, please check this link.
– Taras
Dec 5 '18 at 6:51
1
Simplest the best, no pre-logic script, no argument ordering.
– fatih_dur
Dec 5 '18 at 8:03
add a comment |
Python has ternary conditional operator:
!B! if !A! == 25 else !A!
@nish, to get more information about a shortcut conditional expression, please check this link.
– Taras
Dec 5 '18 at 6:51
1
Simplest the best, no pre-logic script, no argument ordering.
– fatih_dur
Dec 5 '18 at 8:03
add a comment |
Python has ternary conditional operator:
!B! if !A! == 25 else !A!
Python has ternary conditional operator:
!B! if !A! == 25 else !A!
answered Dec 5 '18 at 6:48
FelixIPFelixIP
16.1k11642
16.1k11642
@nish, to get more information about a shortcut conditional expression, please check this link.
– Taras
Dec 5 '18 at 6:51
1
Simplest the best, no pre-logic script, no argument ordering.
– fatih_dur
Dec 5 '18 at 8:03
add a comment |
@nish, to get more information about a shortcut conditional expression, please check this link.
– Taras
Dec 5 '18 at 6:51
1
Simplest the best, no pre-logic script, no argument ordering.
– fatih_dur
Dec 5 '18 at 8:03
@nish, to get more information about a shortcut conditional expression, please check this link.
– Taras
Dec 5 '18 at 6:51
@nish, to get more information about a shortcut conditional expression, please check this link.
– Taras
Dec 5 '18 at 6:51
1
1
Simplest the best, no pre-logic script, no argument ordering.
– fatih_dur
Dec 5 '18 at 8:03
Simplest the best, no pre-logic script, no argument ordering.
– fatih_dur
Dec 5 '18 at 8:03
add a comment |
You can use Field Calculator (see examples here) or the da.UpdateCursor like below. Change input and field names and execute in the python window of ArcMap.
import arcpy
fc = r'C:data.gdbfeature_class' #Change to match your data
fields = ['A','B','C'] #Change to match your data
with arcpy.da.UpdateCursor(fc,fields) as cursor:
for row in cursor:
if row[0] == 25:
row[2] = row[1]
else:
row[2] = row[0]
cursor.updateRow(row)
1
Thank you. But i wasn't sure where to input this code.
– nish
Dec 5 '18 at 6:43
1
@BERA, have you ever used any GIS with GUI? =)
– Taras
Dec 5 '18 at 7:05
1
@BERA, P.S. as always a perfect answer
– Taras
Dec 5 '18 at 8:14
add a comment |
You can use Field Calculator (see examples here) or the da.UpdateCursor like below. Change input and field names and execute in the python window of ArcMap.
import arcpy
fc = r'C:data.gdbfeature_class' #Change to match your data
fields = ['A','B','C'] #Change to match your data
with arcpy.da.UpdateCursor(fc,fields) as cursor:
for row in cursor:
if row[0] == 25:
row[2] = row[1]
else:
row[2] = row[0]
cursor.updateRow(row)
1
Thank you. But i wasn't sure where to input this code.
– nish
Dec 5 '18 at 6:43
1
@BERA, have you ever used any GIS with GUI? =)
– Taras
Dec 5 '18 at 7:05
1
@BERA, P.S. as always a perfect answer
– Taras
Dec 5 '18 at 8:14
add a comment |
You can use Field Calculator (see examples here) or the da.UpdateCursor like below. Change input and field names and execute in the python window of ArcMap.
import arcpy
fc = r'C:data.gdbfeature_class' #Change to match your data
fields = ['A','B','C'] #Change to match your data
with arcpy.da.UpdateCursor(fc,fields) as cursor:
for row in cursor:
if row[0] == 25:
row[2] = row[1]
else:
row[2] = row[0]
cursor.updateRow(row)
You can use Field Calculator (see examples here) or the da.UpdateCursor like below. Change input and field names and execute in the python window of ArcMap.
import arcpy
fc = r'C:data.gdbfeature_class' #Change to match your data
fields = ['A','B','C'] #Change to match your data
with arcpy.da.UpdateCursor(fc,fields) as cursor:
for row in cursor:
if row[0] == 25:
row[2] = row[1]
else:
row[2] = row[0]
cursor.updateRow(row)
edited Dec 5 '18 at 6:45
answered Dec 5 '18 at 6:14
BERABERA
15.5k52042
15.5k52042
1
Thank you. But i wasn't sure where to input this code.
– nish
Dec 5 '18 at 6:43
1
@BERA, have you ever used any GIS with GUI? =)
– Taras
Dec 5 '18 at 7:05
1
@BERA, P.S. as always a perfect answer
– Taras
Dec 5 '18 at 8:14
add a comment |
1
Thank you. But i wasn't sure where to input this code.
– nish
Dec 5 '18 at 6:43
1
@BERA, have you ever used any GIS with GUI? =)
– Taras
Dec 5 '18 at 7:05
1
@BERA, P.S. as always a perfect answer
– Taras
Dec 5 '18 at 8:14
1
1
Thank you. But i wasn't sure where to input this code.
– nish
Dec 5 '18 at 6:43
Thank you. But i wasn't sure where to input this code.
– nish
Dec 5 '18 at 6:43
1
1
@BERA, have you ever used any GIS with GUI? =)
– Taras
Dec 5 '18 at 7:05
@BERA, have you ever used any GIS with GUI? =)
– Taras
Dec 5 '18 at 7:05
1
1
@BERA, P.S. as always a perfect answer
– Taras
Dec 5 '18 at 8:14
@BERA, P.S. as always a perfect answer
– Taras
Dec 5 '18 at 8:14
add a comment |
In the Field Calculator with a usage of Python parser, please type
Pre-Logic Script Code:
def CalcColumn(fieldA, fieldB):
if fieldA == 25:
return fieldB
else:
return fieldA
C =
CalcColumn(!A!, !B!)
References:
- Basic If/Then in Python Parser of ArcGIS Field Calculator?
- Python script for if/elif condition in field calculator
add a comment |
In the Field Calculator with a usage of Python parser, please type
Pre-Logic Script Code:
def CalcColumn(fieldA, fieldB):
if fieldA == 25:
return fieldB
else:
return fieldA
C =
CalcColumn(!A!, !B!)
References:
- Basic If/Then in Python Parser of ArcGIS Field Calculator?
- Python script for if/elif condition in field calculator
add a comment |
In the Field Calculator with a usage of Python parser, please type
Pre-Logic Script Code:
def CalcColumn(fieldA, fieldB):
if fieldA == 25:
return fieldB
else:
return fieldA
C =
CalcColumn(!A!, !B!)
References:
- Basic If/Then in Python Parser of ArcGIS Field Calculator?
- Python script for if/elif condition in field calculator
In the Field Calculator with a usage of Python parser, please type
Pre-Logic Script Code:
def CalcColumn(fieldA, fieldB):
if fieldA == 25:
return fieldB
else:
return fieldA
C =
CalcColumn(!A!, !B!)
References:
- Basic If/Then in Python Parser of ArcGIS Field Calculator?
- Python script for if/elif condition in field calculator
answered Dec 5 '18 at 6:27
TarasTaras
2,0192624
2,0192624
add a comment |
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f305018%2fcreating-new-field-in-arcgis-desktop-which-contains-values-from-two-different-co%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown