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?
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