0

I am trying to calculate field with the formula. I tried arcpy.calculate field management but still having difficulty.

(10/10.4*(100*(math.exp(0.000871* !A!)-1+math.exp(0.000537* !B! )-1+math.exp(0.000487* !C! )-1)))

I used the below code.

with arcpy.da.UpdateCursor(fc, (VALUE, A, B, C)) as cursor: for row in cursor: row[0] = (10/10.4*(100*(math.exp(0.000871* !A!)-1+math.exp(0.000537* !B! )-1+math.exp(0.000487* !C! )-1))) cursor.updateRow()

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Nov 22, 2018 at 18:41
3
  • A field cannot do a calculation by itself. Fields do not have a 'calculation' type. Just text, integers, floats, etc. You may want to look into using a database 'view' which can include automatic calculation columns. In ArcGIS, you can use a 'Query Layer' which is essentially a layer based on a spatial view definition. Or you can just create a spatial view and drag it onto ArcMap. I haven't checked, but there may be arcpy equivalents for doing similar things, but you should probably explain further what you are actually trying to achieve. Commented Nov 23, 2018 at 2:02
  • 3
    Please use code block formatting on code. All it takes is indenting four spaces or using the {} button in the editor. The result will be legible code (and fewer downsides) Commented Nov 24, 2018 at 17:28
  • 1
    And please don't re-ask questions. All you needed to do was make the code edit and vote to reopen. Commented Nov 24, 2018 at 19:49

1 Answer 1

2
#You need to reference each Field its Index in your list of Fields.
# what values are in A,B,C? string, integer,double? you may need to cast them
with arcpy.da.UpdateCursor(fc, ['VALUE', 'A', 'B', 'C']) as cursor: 
 for row in cursor:
 calc_a = math.exp(0.000871* row[1])-1
 calc_b = math.exp(0.000871* row[2])-1
 calc_c = math.exp(0.000871* row[3])-1
 row[0] = (10/10.4 * (100* (calc_a + calc_b + calc_c))))
 cursor.updateRow()
answered Nov 24, 2018 at 17:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.