I'm trying to calculate a field (using idle python to write my scipt and working with ArcMap 10.3) by dividing two fields then dividing by a variable that holds a number, which the number was calculated by dividing 2 sums.
So essentially I'm trying to divide two ratios but I'm having trouble going about that. Basically the equation is ( a / b ) / ( sum(x) / sum(y))
.
I have the variable set to hold the number of the second ratio of (sum(x) / sum(y))
but can't figure out how to incorporate the variable into the calculate field expression or how to set up a double division in the expression. As you can see I used TableToNumPyArray to figure out the sum ratio.
field = arcpy.da.TableToNumPyArray (fc, ["E_Total", "E__Black"], skip_nulls=True)
LQC = 1.0 *(field["E__Black"].sum()) / (field["E_Total"].sum())
#Fields are in long format, 1.0* forces it to be in float format and this section of the code works!
field = arcpy.da.TableToNumPyArray (fc, ["E_Total", "E__Black"], skip_nulls=True)
Lratio = 1.0 *(field["E__Black"]) / (field["E_Total"])
expression = '(!'+Lratio+'!/!'+LQC+'!)'
arcpy.CalculateField_management(lyr, "LQ_Black", expression, "PYTHON")