Copying/replacing first letter in column of attribute table in ArcMap with field calculator and Python Parser? [on hold] The 2019 Stack Overflow Developer Survey Results Are InRounding column in attribute table using ArcGIS Field Calculator?Replacing attribute table entries using Python scriptFinding and copying text with Field Calculator in ArcGIS for Desktop?ArcGIS field calculator Python generate random point names from attribute tableReplacing multiple values in attribute table field using ArcGIS field calculator and python parser?Replacing values with non-English characters in attribute table field using ArcGIS field calculator and python parser?Make ArcMap label using the first letter from each word in an attributeReclassifying Vector Field using python parser in field calculatorSplitting second word of attribute using Python Parser of ArcMap Field Calculator?Extracting numbers from string field but omit some unnecessary cells using Python Parser of ArcMap Field Calculator?
What does "sndry explns" mean in one of the Hitchhiker's guide books?
How to manage monthly salary
What is the use of option -o in the useradd command?
How are circuits which use complex ICs normally simulated?
I looked up a future colleague on linkedin before I started a job. I told my colleague about it and he seemed surprised. Should I apologize?
Where does the "burst of radiance" from Holy Weapon originate?
Which Sci-Fi work first showed weapon of galactic-scale mass destruction?
Can we apply L'Hospital's rule where the derivative is not continuous?
What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?
In microwave frequencies, do you use a circulator when you need a (near) perfect diode?
How to create dashed lines/arrows in Illustrator
What function has this graph?
What is the meaning of Triage in Cybersec world?
What are the advantages and disadvantages of running one shots compared to campaigns?
What do hard-Brexiteers want with respect to the Irish border?
Deadlock Graph and Interpretation, solution to avoid
Does a dangling wire really electrocute me if I'm standing in water?
How long do I have to send payment?
Should I write numbers in words or as symbols in this case?
Unbreakable Formation vs. Cry of the Carnarium
Why is the maximum length of openwrt’s root password 8 characters?
Extreme, unacceptable situation and I can't attend work tomorrow morning
On the insanity of kings as an argument against Monarchy
How to deal with fear of taking dependencies
Copying/replacing first letter in column of attribute table in ArcMap with field calculator and Python Parser? [on hold]
The 2019 Stack Overflow Developer Survey Results Are InRounding column in attribute table using ArcGIS Field Calculator?Replacing attribute table entries using Python scriptFinding and copying text with Field Calculator in ArcGIS for Desktop?ArcGIS field calculator Python generate random point names from attribute tableReplacing multiple values in attribute table field using ArcGIS field calculator and python parser?Replacing values with non-English characters in attribute table field using ArcGIS field calculator and python parser?Make ArcMap label using the first letter from each word in an attributeReclassifying Vector Field using python parser in field calculatorSplitting second word of attribute using Python Parser of ArcMap Field Calculator?Extracting numbers from string field but omit some unnecessary cells using Python Parser of ArcMap Field Calculator?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
How to copy / replace the first letter in a column if that letter is "N" and replace with "C" in the field name "DISTRICT" inside the attribute table in ArcMap using Python inside the field calculator?
arcgis-desktop arcmap field-calculator python-parser
put on hold as off-topic by Dan C, Kadir Şahbaz, csk, BERA, ahmadhanb Apr 5 at 1:08
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – Dan C, Kadir Şahbaz, csk, BERA, ahmadhanb
add a comment |
How to copy / replace the first letter in a column if that letter is "N" and replace with "C" in the field name "DISTRICT" inside the attribute table in ArcMap using Python inside the field calculator?
arcgis-desktop arcmap field-calculator python-parser
put on hold as off-topic by Dan C, Kadir Şahbaz, csk, BERA, ahmadhanb Apr 5 at 1:08
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – Dan C, Kadir Şahbaz, csk, BERA, ahmadhanb
add a comment |
How to copy / replace the first letter in a column if that letter is "N" and replace with "C" in the field name "DISTRICT" inside the attribute table in ArcMap using Python inside the field calculator?
arcgis-desktop arcmap field-calculator python-parser
How to copy / replace the first letter in a column if that letter is "N" and replace with "C" in the field name "DISTRICT" inside the attribute table in ArcMap using Python inside the field calculator?
arcgis-desktop arcmap field-calculator python-parser
arcgis-desktop arcmap field-calculator python-parser
edited Apr 4 at 19:46
PolyGeo♦
53.9k1781246
53.9k1781246
asked Apr 4 at 15:38
Anthony StokesAnthony Stokes
947
947
put on hold as off-topic by Dan C, Kadir Şahbaz, csk, BERA, ahmadhanb Apr 5 at 1:08
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – Dan C, Kadir Şahbaz, csk, BERA, ahmadhanb
put on hold as off-topic by Dan C, Kadir Şahbaz, csk, BERA, ahmadhanb Apr 5 at 1:08
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – Dan C, Kadir Şahbaz, csk, BERA, ahmadhanb
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
The general format for overall string replace in Python in the Field Calculator is
= !stringvar!.replace("substring to find", "new substring")
If you want to only change the first initial for all records, you could build this based on a slice of the string.
= "C" + !stringvar![1:]
If you only want to change the first initial if it starts with a "N", then you're getting into conditional statements (if/then) and should wrap this in a function for use within the Field Calculator. Build this in the codebook/pre-Logic script code.
def replaceIfN(fieldtochange):
if fieldtochange.lower().startswith("n"): # handles both n and N
return "C" + fieldtochange[1:]
else: # no change made
return fieldtochange
Run this with
= replaceIfN(!DISTRICT!)
See http://desktop.arcgis.com/en/arcmap/10.3/manage-data/tables/calculate-field-examples.htm
The conditional statement is the solution I was looking for.
– Anthony Stokes
Apr 4 at 16:32
add a comment |
You don't even have to write any code!
Simply edit the table and do a find and replace on the selected field.
Example of replacing B with XXX.
Result of replacement
I need to know how to copy / replace the first letter in a column if that letter is "N" and replace with "C" using python inside the field calculator. I don't want to replace every instance of "N". This would require some code.
– Anthony Stokes
Apr 4 at 16:38
1
Well... if you look at the image, what does Text match say... You can use @Jackson_Dunn's approach if you intend to wrap the field calculate in say modelbuilder. If you just want to replace the first N with C then my approach is less painful and quicker.
– Hornbydd
Apr 4 at 16:45
1
I see what you mean. This is the fastest way without code but I like to always know the python equivalent.
– Anthony Stokes
Apr 4 at 17:12
Are imgur images always going to be on the site, or is there a risk of them not loading at some distant point in the future? If the latter, please elaborate on your answer (e.g. Select "Start of Field" for Text match)
– smiller
Apr 4 at 18:01
2
I didnt know of find and replace, nice!
– BERA
Apr 4 at 18:53
|
show 3 more comments
You can add a number to the python replace code to determine how many instances to change (in your case just one):
!District!.replace("C", "N", 1)
New contributor
Thanks @Jackson Dunn. I'd be curious as to performance between the string replace number of instances vs. string slicing. I suspect in this case it's minimal but may be worth testing on larger fields or more complex replacements.
– smiller
Apr 4 at 19:52
add a comment |
Using vbscript instead if you're working in ArcGIS Desktop, The code is:
REPLACE ([DISTRICT],"C","N",1,1)
Where :
- the first 1 equals the line position (first character)
- and the second 1 is amount of characters to change (only need to change one letter per row, not all C's and N's).
New contributor
This is the VB script solution so thank you for that but I was wondering how to solve it using python in the field calculator.
– Anthony Stokes
Apr 4 at 16:12
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
The general format for overall string replace in Python in the Field Calculator is
= !stringvar!.replace("substring to find", "new substring")
If you want to only change the first initial for all records, you could build this based on a slice of the string.
= "C" + !stringvar![1:]
If you only want to change the first initial if it starts with a "N", then you're getting into conditional statements (if/then) and should wrap this in a function for use within the Field Calculator. Build this in the codebook/pre-Logic script code.
def replaceIfN(fieldtochange):
if fieldtochange.lower().startswith("n"): # handles both n and N
return "C" + fieldtochange[1:]
else: # no change made
return fieldtochange
Run this with
= replaceIfN(!DISTRICT!)
See http://desktop.arcgis.com/en/arcmap/10.3/manage-data/tables/calculate-field-examples.htm
The conditional statement is the solution I was looking for.
– Anthony Stokes
Apr 4 at 16:32
add a comment |
The general format for overall string replace in Python in the Field Calculator is
= !stringvar!.replace("substring to find", "new substring")
If you want to only change the first initial for all records, you could build this based on a slice of the string.
= "C" + !stringvar![1:]
If you only want to change the first initial if it starts with a "N", then you're getting into conditional statements (if/then) and should wrap this in a function for use within the Field Calculator. Build this in the codebook/pre-Logic script code.
def replaceIfN(fieldtochange):
if fieldtochange.lower().startswith("n"): # handles both n and N
return "C" + fieldtochange[1:]
else: # no change made
return fieldtochange
Run this with
= replaceIfN(!DISTRICT!)
See http://desktop.arcgis.com/en/arcmap/10.3/manage-data/tables/calculate-field-examples.htm
The conditional statement is the solution I was looking for.
– Anthony Stokes
Apr 4 at 16:32
add a comment |
The general format for overall string replace in Python in the Field Calculator is
= !stringvar!.replace("substring to find", "new substring")
If you want to only change the first initial for all records, you could build this based on a slice of the string.
= "C" + !stringvar![1:]
If you only want to change the first initial if it starts with a "N", then you're getting into conditional statements (if/then) and should wrap this in a function for use within the Field Calculator. Build this in the codebook/pre-Logic script code.
def replaceIfN(fieldtochange):
if fieldtochange.lower().startswith("n"): # handles both n and N
return "C" + fieldtochange[1:]
else: # no change made
return fieldtochange
Run this with
= replaceIfN(!DISTRICT!)
See http://desktop.arcgis.com/en/arcmap/10.3/manage-data/tables/calculate-field-examples.htm
The general format for overall string replace in Python in the Field Calculator is
= !stringvar!.replace("substring to find", "new substring")
If you want to only change the first initial for all records, you could build this based on a slice of the string.
= "C" + !stringvar![1:]
If you only want to change the first initial if it starts with a "N", then you're getting into conditional statements (if/then) and should wrap this in a function for use within the Field Calculator. Build this in the codebook/pre-Logic script code.
def replaceIfN(fieldtochange):
if fieldtochange.lower().startswith("n"): # handles both n and N
return "C" + fieldtochange[1:]
else: # no change made
return fieldtochange
Run this with
= replaceIfN(!DISTRICT!)
See http://desktop.arcgis.com/en/arcmap/10.3/manage-data/tables/calculate-field-examples.htm
answered Apr 4 at 16:23
smillersmiller
2,284217
2,284217
The conditional statement is the solution I was looking for.
– Anthony Stokes
Apr 4 at 16:32
add a comment |
The conditional statement is the solution I was looking for.
– Anthony Stokes
Apr 4 at 16:32
The conditional statement is the solution I was looking for.
– Anthony Stokes
Apr 4 at 16:32
The conditional statement is the solution I was looking for.
– Anthony Stokes
Apr 4 at 16:32
add a comment |
You don't even have to write any code!
Simply edit the table and do a find and replace on the selected field.
Example of replacing B with XXX.
Result of replacement
I need to know how to copy / replace the first letter in a column if that letter is "N" and replace with "C" using python inside the field calculator. I don't want to replace every instance of "N". This would require some code.
– Anthony Stokes
Apr 4 at 16:38
1
Well... if you look at the image, what does Text match say... You can use @Jackson_Dunn's approach if you intend to wrap the field calculate in say modelbuilder. If you just want to replace the first N with C then my approach is less painful and quicker.
– Hornbydd
Apr 4 at 16:45
1
I see what you mean. This is the fastest way without code but I like to always know the python equivalent.
– Anthony Stokes
Apr 4 at 17:12
Are imgur images always going to be on the site, or is there a risk of them not loading at some distant point in the future? If the latter, please elaborate on your answer (e.g. Select "Start of Field" for Text match)
– smiller
Apr 4 at 18:01
2
I didnt know of find and replace, nice!
– BERA
Apr 4 at 18:53
|
show 3 more comments
You don't even have to write any code!
Simply edit the table and do a find and replace on the selected field.
Example of replacing B with XXX.
Result of replacement
I need to know how to copy / replace the first letter in a column if that letter is "N" and replace with "C" using python inside the field calculator. I don't want to replace every instance of "N". This would require some code.
– Anthony Stokes
Apr 4 at 16:38
1
Well... if you look at the image, what does Text match say... You can use @Jackson_Dunn's approach if you intend to wrap the field calculate in say modelbuilder. If you just want to replace the first N with C then my approach is less painful and quicker.
– Hornbydd
Apr 4 at 16:45
1
I see what you mean. This is the fastest way without code but I like to always know the python equivalent.
– Anthony Stokes
Apr 4 at 17:12
Are imgur images always going to be on the site, or is there a risk of them not loading at some distant point in the future? If the latter, please elaborate on your answer (e.g. Select "Start of Field" for Text match)
– smiller
Apr 4 at 18:01
2
I didnt know of find and replace, nice!
– BERA
Apr 4 at 18:53
|
show 3 more comments
You don't even have to write any code!
Simply edit the table and do a find and replace on the selected field.
Example of replacing B with XXX.
Result of replacement
You don't even have to write any code!
Simply edit the table and do a find and replace on the selected field.
Example of replacing B with XXX.
Result of replacement
answered Apr 4 at 16:19
HornbyddHornbydd
27.1k32958
27.1k32958
I need to know how to copy / replace the first letter in a column if that letter is "N" and replace with "C" using python inside the field calculator. I don't want to replace every instance of "N". This would require some code.
– Anthony Stokes
Apr 4 at 16:38
1
Well... if you look at the image, what does Text match say... You can use @Jackson_Dunn's approach if you intend to wrap the field calculate in say modelbuilder. If you just want to replace the first N with C then my approach is less painful and quicker.
– Hornbydd
Apr 4 at 16:45
1
I see what you mean. This is the fastest way without code but I like to always know the python equivalent.
– Anthony Stokes
Apr 4 at 17:12
Are imgur images always going to be on the site, or is there a risk of them not loading at some distant point in the future? If the latter, please elaborate on your answer (e.g. Select "Start of Field" for Text match)
– smiller
Apr 4 at 18:01
2
I didnt know of find and replace, nice!
– BERA
Apr 4 at 18:53
|
show 3 more comments
I need to know how to copy / replace the first letter in a column if that letter is "N" and replace with "C" using python inside the field calculator. I don't want to replace every instance of "N". This would require some code.
– Anthony Stokes
Apr 4 at 16:38
1
Well... if you look at the image, what does Text match say... You can use @Jackson_Dunn's approach if you intend to wrap the field calculate in say modelbuilder. If you just want to replace the first N with C then my approach is less painful and quicker.
– Hornbydd
Apr 4 at 16:45
1
I see what you mean. This is the fastest way without code but I like to always know the python equivalent.
– Anthony Stokes
Apr 4 at 17:12
Are imgur images always going to be on the site, or is there a risk of them not loading at some distant point in the future? If the latter, please elaborate on your answer (e.g. Select "Start of Field" for Text match)
– smiller
Apr 4 at 18:01
2
I didnt know of find and replace, nice!
– BERA
Apr 4 at 18:53
I need to know how to copy / replace the first letter in a column if that letter is "N" and replace with "C" using python inside the field calculator. I don't want to replace every instance of "N". This would require some code.
– Anthony Stokes
Apr 4 at 16:38
I need to know how to copy / replace the first letter in a column if that letter is "N" and replace with "C" using python inside the field calculator. I don't want to replace every instance of "N". This would require some code.
– Anthony Stokes
Apr 4 at 16:38
1
1
Well... if you look at the image, what does Text match say... You can use @Jackson_Dunn's approach if you intend to wrap the field calculate in say modelbuilder. If you just want to replace the first N with C then my approach is less painful and quicker.
– Hornbydd
Apr 4 at 16:45
Well... if you look at the image, what does Text match say... You can use @Jackson_Dunn's approach if you intend to wrap the field calculate in say modelbuilder. If you just want to replace the first N with C then my approach is less painful and quicker.
– Hornbydd
Apr 4 at 16:45
1
1
I see what you mean. This is the fastest way without code but I like to always know the python equivalent.
– Anthony Stokes
Apr 4 at 17:12
I see what you mean. This is the fastest way without code but I like to always know the python equivalent.
– Anthony Stokes
Apr 4 at 17:12
Are imgur images always going to be on the site, or is there a risk of them not loading at some distant point in the future? If the latter, please elaborate on your answer (e.g. Select "Start of Field" for Text match)
– smiller
Apr 4 at 18:01
Are imgur images always going to be on the site, or is there a risk of them not loading at some distant point in the future? If the latter, please elaborate on your answer (e.g. Select "Start of Field" for Text match)
– smiller
Apr 4 at 18:01
2
2
I didnt know of find and replace, nice!
– BERA
Apr 4 at 18:53
I didnt know of find and replace, nice!
– BERA
Apr 4 at 18:53
|
show 3 more comments
You can add a number to the python replace code to determine how many instances to change (in your case just one):
!District!.replace("C", "N", 1)
New contributor
Thanks @Jackson Dunn. I'd be curious as to performance between the string replace number of instances vs. string slicing. I suspect in this case it's minimal but may be worth testing on larger fields or more complex replacements.
– smiller
Apr 4 at 19:52
add a comment |
You can add a number to the python replace code to determine how many instances to change (in your case just one):
!District!.replace("C", "N", 1)
New contributor
Thanks @Jackson Dunn. I'd be curious as to performance between the string replace number of instances vs. string slicing. I suspect in this case it's minimal but may be worth testing on larger fields or more complex replacements.
– smiller
Apr 4 at 19:52
add a comment |
You can add a number to the python replace code to determine how many instances to change (in your case just one):
!District!.replace("C", "N", 1)
New contributor
You can add a number to the python replace code to determine how many instances to change (in your case just one):
!District!.replace("C", "N", 1)
New contributor
edited Apr 4 at 19:54
PolyGeo♦
53.9k1781246
53.9k1781246
New contributor
answered Apr 4 at 18:31
Jackson DunnJackson Dunn
292
292
New contributor
New contributor
Thanks @Jackson Dunn. I'd be curious as to performance between the string replace number of instances vs. string slicing. I suspect in this case it's minimal but may be worth testing on larger fields or more complex replacements.
– smiller
Apr 4 at 19:52
add a comment |
Thanks @Jackson Dunn. I'd be curious as to performance between the string replace number of instances vs. string slicing. I suspect in this case it's minimal but may be worth testing on larger fields or more complex replacements.
– smiller
Apr 4 at 19:52
Thanks @Jackson Dunn. I'd be curious as to performance between the string replace number of instances vs. string slicing. I suspect in this case it's minimal but may be worth testing on larger fields or more complex replacements.
– smiller
Apr 4 at 19:52
Thanks @Jackson Dunn. I'd be curious as to performance between the string replace number of instances vs. string slicing. I suspect in this case it's minimal but may be worth testing on larger fields or more complex replacements.
– smiller
Apr 4 at 19:52
add a comment |
Using vbscript instead if you're working in ArcGIS Desktop, The code is:
REPLACE ([DISTRICT],"C","N",1,1)
Where :
- the first 1 equals the line position (first character)
- and the second 1 is amount of characters to change (only need to change one letter per row, not all C's and N's).
New contributor
This is the VB script solution so thank you for that but I was wondering how to solve it using python in the field calculator.
– Anthony Stokes
Apr 4 at 16:12
add a comment |
Using vbscript instead if you're working in ArcGIS Desktop, The code is:
REPLACE ([DISTRICT],"C","N",1,1)
Where :
- the first 1 equals the line position (first character)
- and the second 1 is amount of characters to change (only need to change one letter per row, not all C's and N's).
New contributor
This is the VB script solution so thank you for that but I was wondering how to solve it using python in the field calculator.
– Anthony Stokes
Apr 4 at 16:12
add a comment |
Using vbscript instead if you're working in ArcGIS Desktop, The code is:
REPLACE ([DISTRICT],"C","N",1,1)
Where :
- the first 1 equals the line position (first character)
- and the second 1 is amount of characters to change (only need to change one letter per row, not all C's and N's).
New contributor
Using vbscript instead if you're working in ArcGIS Desktop, The code is:
REPLACE ([DISTRICT],"C","N",1,1)
Where :
- the first 1 equals the line position (first character)
- and the second 1 is amount of characters to change (only need to change one letter per row, not all C's and N's).
New contributor
edited Apr 4 at 19:49
PolyGeo♦
53.9k1781246
53.9k1781246
New contributor
answered Apr 4 at 15:54
Jackson DunnJackson Dunn
292
292
New contributor
New contributor
This is the VB script solution so thank you for that but I was wondering how to solve it using python in the field calculator.
– Anthony Stokes
Apr 4 at 16:12
add a comment |
This is the VB script solution so thank you for that but I was wondering how to solve it using python in the field calculator.
– Anthony Stokes
Apr 4 at 16:12
This is the VB script solution so thank you for that but I was wondering how to solve it using python in the field calculator.
– Anthony Stokes
Apr 4 at 16:12
This is the VB script solution so thank you for that but I was wondering how to solve it using python in the field calculator.
– Anthony Stokes
Apr 4 at 16:12
add a comment |