Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is my first post, so any help is greatly appreciated. I'm trying to use an update cursor to calculate a field. Basically, I'm trying to avoid division by 0 by looking in row[0] and see if it's 0. My code thus far is:

import arcpy
fields=('MEAN_GRIDC', 'SUM_Join_C', 'crimeRate')
with arcpy.da.UpdateCursor(fc,fields) as cursor:
    for row in cursor:
        if (row[0] > 0):
            row[2] = row[1]/row[0]
            row[2] = 0

Any ideas or help on what I'm missing? I can only assume (yes I know what assuming does) that it's the calculation aspect of my code. Thanks!!!

UPDATE: Sorry for the ridiculous question. I continually thought it was in the division of rows, so I looked into my fields a little closer. Turns out, Row[0] and Row[1] were Double and Row[2] was Long. Fixed that aspect and the code works as is.


migration rejected from Nov 10 '14 at 12:11

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as off-topic by Fezter, user30184, AndreJ, BradHards, Erica Nov 10 '14 at 12:11

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Fezter, user30184, Erica
  • "Questions about software development are off-topic here unless they relate directly to Geographical Information Systems, but they can be asked on Stack Overflow." – AndreJ, BradHards
If this question can be reworded to fit the rules in the help center, please edit the question.

Please consider adding your solution as an answer so we can consider this question answered. – Aaron Nov 9 '14 at 23:58