I am trying to conditionally change the value of a current row, based on the value of the Nth row below it. say for example I have a csv file that looks like:
trial
''
''
''
''
''
''
''
'a'
''
''
''
''
''
''
''
'a'
''
''
''
''
''
''
''
'a'
Now,if the value of every 3rd row after the current row is 'a', then the null will be converted into 'a' from the current row to the 3rd row below. as such:
trial
''
''
''
''
'a'
'a'
'a'
'a'
''
''
''
''
'a'
'a'
'a'
'a'
''
''
''
''
'a'
'a'
'a'
'a'
my code is as follow:
data =csv.reader(data)
next(data)
def convert(param):
if param=='':
value='a'
else:
value=''
return value
for row in data:
i=0
for line in islice(data, i+3, None):
print i
print line
print row
if line==['a']:
convert(row)
print row
i = i+1
however, the output is:
0
[]
[]
[]
1
[]
[]
[]
2
[]
[]
[]
3
['a']
[]
[]
4
[]
[]
[]
5
[]
[]
[]
6
[]
[]
[]
7
[]
[]
[]
8
[]
[]
[]
9
[]
[]
[]
10
[]
[]
[]
11
[]
[]
[]
12
[]
[]
[]
13
['a']
[]
[]
14
[]
[]
[]
15
[]
[]
[]
16
[]
[]
[]
17
[]
[]
[]
18
[]
[]
[]
19
[]
[]
[]
20
[]
[]
[]
21
[]
[]
[]
22
[]
[]
[]
23
['a']
[]
[]
any idea on how to do this?