Question regarding Python and field calculating. I have 4 fields "BaseArea", "SW_Fee", "PT", "IASqFt". I am trying to field calculate the "SW_Fee" field based on a fee structure. My "PT" field has 3 catagories ( 'Residential', 'Industrial', 'Commercial') (more catagories could be added later). My "BaseArea" and "IASqFT" are both long integers.
I need something along the line of " If "PT" equals 'Residential' then look in "BaseArea". If "BaseArea" is >= to 1501 then the fee is $2.50 then if "BaseArea is <= 1500 the fee is $1.50.
BUT if "PT" equals 'Commercial' I have a whole other set of criteria for it to look at.
Any and all help is appreciated.
How are you wanting to implement this calculation? A cursor? Field Calculator? If the latter, using the GUI or calling through Python?
Is your issue how to use a cursor or field calculator to do this, or is your issue more not knowing how to implement logic structures in Python?
I recommend an update cursor as well. If you really want to use the field calculator, use the GUI and don't try to call it from Python because doing so requires define the code block as a string, and I always find building nested logic structures as a string can get confusing for folks new to Python.
Personally, I would use a cursor.
Something like this should be a start.
with arcpy.da.UpdateCursor(datasource, ['PT','BaseArea','SW_Fee','IASqFt']) as cursor: for row in cursor: if row == 'Residential': if row >= 1501: row = '$2.50' if row <= 1500: row = '$1.50' elif row == 'Commercial': print '__whole other set__' cursor.updateRow(row) del cursor