Need Help with Math Operand Error

460
3
04-25-2013 02:07 PM
ChristopherClark1
Occasional Contributor
Okay I have the following code
 with arcpy.da.UpdateCursor(fc, fields) as rows:
                    for row in rows:
                        row[2] = row[0] * (32.82010551 * 32.82010551) * (0.000000092903)
                        row[3] = (row[1] *(32.82010551 * 32.82010551) * 25)/(row[0] * (32.82010551 * 32.82010551))
                        rows.updateRow(row)


Where I get this error:

PYTHON ERRORS:
Traceback info:
File "G:\Scripts\Threshold_IP_Scripts\GetStreamStatsA.py", line 32, in StreamStatistics
row[2] = row[0] * (32.82010551 * 32.82010551) * (0.000000092903)

Error Info:
unsupported operand type(s) for *: 'NoneType' and 'float'

ArcPy ERRORS:

Any ideas? I am stuck!
Tags (2)
0 Kudos
3 Replies
MathewCoyle
Frequent Contributor
You probably have a null value in your row.
This should get you around that.
if row[0]:
    row[2] = row[0] * (32.82010551 * 32.82010551) * (0.000000092903)
    if row[1]:
        row[3] = (row[1] *(32.82010551 * 32.82010551) * 25)/(row[0] * (32.82010551 * 32.82010551))
0 Kudos
ChristopherClark1
Occasional Contributor
Sorry I am confused. Where do I put that code?
0 Kudos
ChristopherClark1
Occasional Contributor
Is this correct?

 fields = ['RASTERVALU_12', 'RASTERVALU_12_13', 'Cumm_Dr_SQKM', 'Mean_Pr_MM']
                with arcpy.da.UpdateCursor(fc, fields) as rows:
                    for row in rows:
                        if row[0]:
                            row[2] = row[0] * (32.82010551 * 32.82010551) * (0.000000092903)
                        if row[1]:
                            row[3] = (row[1] *(32.82010551 * 32.82010551) * 25)/(row[0] * (32.82010551 * 32.82010551))
                        rows.updateRow(row)
0 Kudos