8

You can use in to check for membership: if FIELD in veg: return 'Vegetable' elif FIELD in fruit: return 'Fruit' For bonus points use sets, which offer better performance for this: veg = {'Carrot', 'Celery', 'Broccoli'} fruit = {'Apple', 'Banana', 'Grape'}


7

You have made a basic mistake, you have embed the variable you called field directly within a text expression, i.e. within the "", so it sees it as some text not as a variable. Do something like this: expression = "!Classific!.replace(!Classific!,'" + field + "')" shapes2=arcpy.CalculateField_management(shapes1,'Classific',...


5

You just need to double the problematic apostrophe so the expression become : 'Christy''s Yard'


5

If the layer is already georeferenced in QGIS then you can do something like this with the Field Calculator: Expression for longitude: x(transform($geometry, @YOUR_CRS_ID, 'EPSG:4326')) And for latitude: y(transform($geometry, @YOUR_CRS_ID, 'EPSG:4326')) If the layer is not georeferenced and you want the fields to be calculated based on the X and Y fields ...


4

You can use this expression: array_find(array_agg("BUILDING"||'_'||-$id,"BUILDING"),"BUILDING"||'_'||-$id)+1 Result:


4

Also you can escape the apostrophe with backslash \


4

in order to use the value of a variable in a text string, I recommend to use .format(). in practice, write your string with missing parameter in between {} then list all parameters in the format function (separated by ,) arcpy.AddField_management(shapes,'Classific','TEXT') arcpy.CalculateField_management(shapes,'Classific',"!Classific!.replace(!...


3

Try concatenating the phrase together using a char code: 'Christy' || CHAR(39) || 's yard' EDIT: Yeah @J.R's answer is better, +1


2

You try the following code in the codeblock of Field Calculator: def sort_name(n): split = n.split() if len(split) == 0: return '' elif len(split) < 3: return ('{0} {1}').format(split[1], split[0]) else: return ('{0} {1} {2}').format(split[1], split[2], split[0]) The code split the text in the field and create a ...


2

I always prefer to use an UpdateCursor to update feature attributes, mainly because I find the syntax more readable and Esri has gone a long way in optimizing cursor performance. I would also recommend using the .lower() method to make sure case does not matter when checking your check lists. For example: import arcpy fc = r'C:\path\to\your\geodatabase.gdb\...


1

You can do this using virtual fields. In the field calculator check the Create virtual field button: When you add or edit a record or close and reopen the attribute table this will recaulcuate update on the fly. For example if I create a virtual field for a polygon layer with the expression $area then when I create a new polygon it will automatically ...


Only top voted, non community-wiki answers of a minimum length are eligible