'compare two fields in csv file
If I have
csv_reader = csv.DictReader(csv_file)
for line in csv_reader:
if line['Title'] == ???:
and want to check if the field in each line (row) in column Title is the same as the field right after it in the next line.
For extra clarification: if you consider row to be x and column to be y: I want to check if (row, column) == (row + 1, column) where column is called Title.
How can I achieve this? I tried doing
if line['Title'] == next(line)['Title']:
but it doesn't work.
Solution 1:[1]
there is many ways to achieve it, but one of them is this
csv_reader = list(csv.DictReader(csv_file))
for i in range(len(csv_reader)-1):
if csv_reader[i]['Title'] == csv_reader[i+1]['Title']:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
