How to copy / replace first letter in a column of attribute table in ArcMap with field calculator and Python?Find and Replace expression needed in Field Calculator ArcGIS 10Rounding column in attribute table using ArcGIS Field Calculator?Capitalizing The First Letter Of Each Word In Attribute FieldHow to add a new column in attribute table with attribute with indexes of another max-min ordered attribute field?How to find/replace element in field with Field CalculatorCapitalizing The First Letter Of Each Word In Attribute Field QGISArcGIS field calculator Python generate random point names from attribute tableArcMap Python script for attribute split, replace and concatenateReplacing multiple values in attribute table field using ArcGIS field calculator and python parser?ArcMap field calculator to replace certain existing values
Why can't we play rap on piano?
Would Slavery Reparations be considered Bills of Attainder and hence Illegal?
Arrow those variables!
Is there a hemisphere-neutral way of specifying a season?
Why does Optional.map make this assignment work?
A geometry theory without irrational numbers?
How can I apply a plugin only to the lower frequencies?
How much of data wrangling is a data scientist's job?
intersection of two sorted vectors in C++
What is going on with Captain Marvel's blood colour?
Can I make "comment-region" comment empty lines?
Can one be a co-translator of a book, if he does not know the language that the book is translated into?
Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?
Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?
Magento 2: Migrate only Customer and orders
Should I tell management that I intend to leave due to bad software development practices?
How can saying a song's name be a copyright violation?
Why doesn't H₄O²⁺ exist?
Western buddy movie with a supernatural twist where a woman turns into an eagle at the end
AES: Why is it a good practice to use only the first 16bytes of a hash for encryption?
Python: return float 1.0 as int 1 but float 1.5 as float 1.5
Alternative to sending password over mail?
Do I have a twin with permutated remainders?
Anagram holiday
How to copy / replace first letter in a column of attribute table in ArcMap with field calculator and Python?
Find and Replace expression needed in Field Calculator ArcGIS 10Rounding column in attribute table using ArcGIS Field Calculator?Capitalizing The First Letter Of Each Word In Attribute FieldHow to add a new column in attribute table with attribute with indexes of another max-min ordered attribute field?How to find/replace element in field with Field CalculatorCapitalizing The First Letter Of Each Word In Attribute Field QGISArcGIS field calculator Python generate random point names from attribute tableArcMap Python script for attribute split, replace and concatenateReplacing multiple values in attribute table field using ArcGIS field calculator and python parser?ArcMap field calculator to replace certain existing values
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?
python arcmap field-calculator attribute-table fields-attributes
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?
python arcmap field-calculator attribute-table fields-attributes
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?
python arcmap field-calculator attribute-table fields-attributes
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?
python arcmap field-calculator attribute-table fields-attributes
python arcmap field-calculator attribute-table fields-attributes
edited 1 hour ago
Vince
14.8k32849
14.8k32849
asked 3 hours ago
Anthony StokesAnthony Stokes
917
917
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
2 hours ago
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
2 hours ago
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
2 hours ago
I see what you mean. This is the fastest way without code but I like to always know the python equivalent.
– Anthony Stokes
2 hours ago
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
1 hour ago
@smiller I only ever paste images into the answer box and have no control over where GIS se puts it.
– Hornbydd
1 hour ago
|
show 2 more comments
Using vbscript instead if you're working in Arc 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
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
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
3 hours ago
add a comment |
Sorry can't comment on the answer by smiller. you can also 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
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
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%2f317805%2fhow-to-copy-replace-first-letter-in-a-column-of-attribute-table-in-arcmap-with%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
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
2 hours ago
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
2 hours ago
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 2 hours ago
smillersmiller
2,209217
2,209217
The conditional statement is the solution I was looking for.
– Anthony Stokes
2 hours ago
add a comment |
The conditional statement is the solution I was looking for.
– Anthony Stokes
2 hours ago
The conditional statement is the solution I was looking for.
– Anthony Stokes
2 hours ago
The conditional statement is the solution I was looking for.
– Anthony Stokes
2 hours ago
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
2 hours ago
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
2 hours ago
I see what you mean. This is the fastest way without code but I like to always know the python equivalent.
– Anthony Stokes
2 hours ago
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
1 hour ago
@smiller I only ever paste images into the answer box and have no control over where GIS se puts it.
– Hornbydd
1 hour ago
|
show 2 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
2 hours ago
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
2 hours ago
I see what you mean. This is the fastest way without code but I like to always know the python equivalent.
– Anthony Stokes
2 hours ago
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
1 hour ago
@smiller I only ever paste images into the answer box and have no control over where GIS se puts it.
– Hornbydd
1 hour ago
|
show 2 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 2 hours ago
HornbyddHornbydd
27.1k32957
27.1k32957
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
2 hours ago
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
2 hours ago
I see what you mean. This is the fastest way without code but I like to always know the python equivalent.
– Anthony Stokes
2 hours ago
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
1 hour ago
@smiller I only ever paste images into the answer box and have no control over where GIS se puts it.
– Hornbydd
1 hour ago
|
show 2 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
2 hours ago
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
2 hours ago
I see what you mean. This is the fastest way without code but I like to always know the python equivalent.
– Anthony Stokes
2 hours ago
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
1 hour ago
@smiller I only ever paste images into the answer box and have no control over where GIS se puts it.
– Hornbydd
1 hour ago
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
2 hours ago
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
2 hours ago
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
2 hours ago
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
2 hours ago
I see what you mean. This is the fastest way without code but I like to always know the python equivalent.
– Anthony Stokes
2 hours ago
I see what you mean. This is the fastest way without code but I like to always know the python equivalent.
– Anthony Stokes
2 hours ago
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
1 hour ago
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
1 hour ago
@smiller I only ever paste images into the answer box and have no control over where GIS se puts it.
– Hornbydd
1 hour ago
@smiller I only ever paste images into the answer box and have no control over where GIS se puts it.
– Hornbydd
1 hour ago
|
show 2 more comments
Using vbscript instead if you're working in Arc 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
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
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
3 hours ago
add a comment |
Using vbscript instead if you're working in Arc 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
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
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
3 hours ago
add a comment |
Using vbscript instead if you're working in Arc 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
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Using vbscript instead if you're working in Arc 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
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 2 hours ago
J. Monticolo
1,393217
1,393217
New contributor
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 3 hours ago
Jackson DunnJackson Dunn
112
112
New contributor
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
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
3 hours ago
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
3 hours ago
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
3 hours ago
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
3 hours ago
add a comment |
Sorry can't comment on the answer by smiller. you can also 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
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Sorry can't comment on the answer by smiller. you can also 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
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Sorry can't comment on the answer by smiller. you can also 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
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Sorry can't comment on the answer by smiller. you can also 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
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 45 mins ago
Jackson DunnJackson Dunn
112
112
New contributor
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Jackson Dunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
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%2f317805%2fhow-to-copy-replace-first-letter-in-a-column-of-attribute-table-in-arcmap-with%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