Creating new field in ArcGIS Desktop which contains values from two different columns with certain...
up vote
1
down vote
favorite
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 |
up vote
1
down vote
favorite
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 |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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 yesterday
PolyGeo♦
53k1779237
53k1779237
asked yesterday
nish
82
82
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
up vote
2
down vote
accepted
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 |
up vote
6
down vote
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
yesterday
1
Simplest the best, no pre-logic script, no argument ordering.
– fatih_dur
yesterday
add a comment |
up vote
3
down vote
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
yesterday
1
@BERA, have you ever used any GIS with GUI? =)
– Taras
yesterday
1
@BERA, P.S. as always a perfect answer
– Taras
yesterday
add a comment |
up vote
2
down vote
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 |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
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 |
up vote
2
down vote
accepted
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 |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
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 yesterday
ahmadhanb
21.2k31951
21.2k31951
add a comment |
add a comment |
up vote
6
down vote
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
yesterday
1
Simplest the best, no pre-logic script, no argument ordering.
– fatih_dur
yesterday
add a comment |
up vote
6
down vote
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
yesterday
1
Simplest the best, no pre-logic script, no argument ordering.
– fatih_dur
yesterday
add a comment |
up vote
6
down vote
up vote
6
down vote
Python has ternary conditional operator:
!B! if !A! == 25 else !A!
Python has ternary conditional operator:
!B! if !A! == 25 else !A!
answered yesterday
FelixIP
15.8k11440
15.8k11440
@nish, to get more information about a shortcut conditional expression, please check this link.
– Taras
yesterday
1
Simplest the best, no pre-logic script, no argument ordering.
– fatih_dur
yesterday
add a comment |
@nish, to get more information about a shortcut conditional expression, please check this link.
– Taras
yesterday
1
Simplest the best, no pre-logic script, no argument ordering.
– fatih_dur
yesterday
@nish, to get more information about a shortcut conditional expression, please check this link.
– Taras
yesterday
@nish, to get more information about a shortcut conditional expression, please check this link.
– Taras
yesterday
1
1
Simplest the best, no pre-logic script, no argument ordering.
– fatih_dur
yesterday
Simplest the best, no pre-logic script, no argument ordering.
– fatih_dur
yesterday
add a comment |
up vote
3
down vote
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
yesterday
1
@BERA, have you ever used any GIS with GUI? =)
– Taras
yesterday
1
@BERA, P.S. as always a perfect answer
– Taras
yesterday
add a comment |
up vote
3
down vote
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
yesterday
1
@BERA, have you ever used any GIS with GUI? =)
– Taras
yesterday
1
@BERA, P.S. as always a perfect answer
– Taras
yesterday
add a comment |
up vote
3
down vote
up vote
3
down vote
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 yesterday
answered yesterday
BERA
13.9k51839
13.9k51839
1
Thank you. But i wasn't sure where to input this code.
– nish
yesterday
1
@BERA, have you ever used any GIS with GUI? =)
– Taras
yesterday
1
@BERA, P.S. as always a perfect answer
– Taras
yesterday
add a comment |
1
Thank you. But i wasn't sure where to input this code.
– nish
yesterday
1
@BERA, have you ever used any GIS with GUI? =)
– Taras
yesterday
1
@BERA, P.S. as always a perfect answer
– Taras
yesterday
1
1
Thank you. But i wasn't sure where to input this code.
– nish
yesterday
Thank you. But i wasn't sure where to input this code.
– nish
yesterday
1
1
@BERA, have you ever used any GIS with GUI? =)
– Taras
yesterday
@BERA, have you ever used any GIS with GUI? =)
– Taras
yesterday
1
1
@BERA, P.S. as always a perfect answer
– Taras
yesterday
@BERA, P.S. as always a perfect answer
– Taras
yesterday
add a comment |
up vote
2
down vote
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 |
up vote
2
down vote
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 |
up vote
2
down vote
up vote
2
down vote
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 yesterday
Taras
1,7622522
1,7622522
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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