I am trying to create a loop that searches through a csv file for rows with a common third and fourth column and performs an operation on them.
The file I have is as follows:
name1,x,y,z,notes
name2,a,b,c,notes
name3,a,y,z,notes
I use code that reads the first row and identifies row [2] and row [3] and searches for all rows in the file for this combination of columns. Unfortunately, I cannot figure out how to look for them.
for row in csvfile:
row_identify = row[2:3]
for row in csvfile:
if row_identify in row:
print row
else:
print "not here"
I want it to print the first and third line (since y and z would be row_identify). I suggested that I could simply indicate that I wanted to search for these lines, but this does not seem to work. I also tried using
row_identify = str(row[2]),str(row[3])
but it doesn’t work either.
source
share