2

I have a .csv with three colums and a point feature class with an empty field that i would like to fill with a value of the csv. In the .csv i have 15 rows with a code. In the feature class just one row and one of the fields has the same code as one of the codes in the csv.

I want to read the feature class field with code, then read the csv and when it find the same code, change the colum in the csv and read the value corresponding to it. And that value which correspond to the coincident code value insert it in the empty field in the point feature class. By now i was trying to use the SearchCursor and csv reader but it seems it doesn't work but also I get no error.

Does anyone know how to do that?

import csv
import arcpy
fc = r'C:\Users\Alumno\Desktop\IGP\IGP.gdb\valor'
with arcpy.da.SearchCursor(fc,['Com__Forest']) as cursor:
...   for row in cursor:
...      comarca = 'row [0]'
...      with open (r'C:\Users\Alumno\Desktop\IGP\FWI.csv','rb')as f:
...          reader = csv.reader  (f,delimiter = ';')
...          if row in reader == comarca in row:
...                 indiceCom = row[2]
...                 print row [2]

my problem is that it is the first time i am leading with python and i am terribly lost. From one side i arrange to compare the value on the csv with one difined value of "Comarca" import csv

comarca = '1'

with open (r'D:\ProyectoIGP_Inigo\FWI.csv','rb') as f:

... reader= csv.reader (f,delimiter = ';')

... for row in reader:

... if row[0] == comarca in row:

... indicecom = row[2]

... print indicecom ... 1

Now i need to change that defined value of "comarca = '1'" for and edit cursor or something that lets me introduce the value of row [2]

Any idea?

  • 2
    Bunch of problems here: You can't update in a SearchCursor. Your if condition will never pass (hint: 'row [0]' is a literal starting with "r"). You've overloaded the variable "row". Knowing the file is small, you could convert it to a dictionary, and remove the nesting. In short, you're making the problem much harder than it needs to be -- break it into small testable pieces, then integrate the pieces. – Vince Apr 24 '16 at 18:19
  • I am confused by you using what appears to be two different accounts: gis.stackexchange.com/users/71921/user71921 and gis.stackexchange.com/users/71902/inigo Please use these instructions to merge them ASAP: gis.stackexchange.com/help/merging-accounts ... and please take the 2-minute Tour that introduces users to how the site works. – PolyGeo Apr 25 '16 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.