#Occurence search in csv file

8 messages · Page 1 of 1 (latest)

rich sapphire
#

Hello guys.
So I created a program which read a csv file with 2 columns and stock values in a and b string variables for each iteration of rows in the file.
The goal was to find the line's number where a==b in b column but the problem is that python return me :
'File ~\Music\po\TEST.py:33 in <module>
a = row1[lines1]

IndexError: list index out of range'

I don't know how to solve it and it been 1 hour that I'm stuck.

N.B : 1st Image : my code | 2nd : my csv file

In advance, thx for your help

rich sapphire
#

UPDATE: I changed my code but a doesn't change but b does

gritty inlet
#

try adding print(row) under your loop and send an example

rich sapphire
#

Sorry I send the wrong program.
Here :

#

And when I add print(row2), it return me all the data :

gritty inlet
#

if your comparing the first and second value in each row you only need one loop

#

just to go thru your rows

#

then a = row[0] and b = row[1] to get the first and second item in the list in each of your rows then you can do your if a == b: