I am a novice in Python as well has having minimal experience with ArcMap. Currently I am using a U.S. Census TIGER file, mapping roads in Harris County, TX. I want to add a new field called SPEED, which will return a speed associated with the MTFCC string (MTFCC is the column which classifies road type. e.g. S1400, S1200, etc.).
I opened my attributes table, added a new field called SPEED, clicked on the Field Calculator of the speed column, and inserted my own Python code. I made sure to click Python (not VB), and have my return value be a number. My code is as follows...
def SpeedCalc(MTFCC):
if MTFCC == "S1400":
return 25
elif MTFCC == "S1200":
return 45
elif MTFCC == "S1100":
return 65
elif MTFCC == "S1630":
return 25
elif MTFCC == "S1730":
return 15
else:
return 9999
I made sure below where 'SPEED = ' is to have "SpeedCalc(!MTFCC!) written. No errors were thrown, but all my columns were listed as 0. I do not have administrative rights to my working computer or else I would insert my code in to Python first and see what is wrong. As far as I'm aware, my syntax is correct and the statement executes but nothing is done. MTFCC are listed as strings in the properties tab.