Hi I want to filter out rows whose 2nd column (Hex) has value 80 or 81 and filter out rows whose 2nd column is 0 only if its below the row which has 81 in the second column:
sample.csv :
Delta,Hex,Type,Time
0,81,DTE,10 pm
1,0,DTE,10 pm
0,01,DTE,10 pm
1,1c,DTE,9 pm
1,0,DTE,10 pm
0,1d,DTE,10 pm
1,0,DTE,10 pm
So here's the script which I wrote which filters out rows with values 80 81 and 0 in the second column(Hex).
Script.py:
import csv
with open('sample.csv', 'r') as f:
rows=csv.DictReader(f, fieldnames=None,restkey=None,restval=None,dialect='excel',delimiter=",")
filtered_rows=filter(lambda p:'80' != p['Hex'] and '81' != p['Hex'] and '0' != p['Hex'], rows)
for i in filtered_rows :
print (i['Hex'])
So it filters out all the rows which has 0 in their second column.
Current output with the above script:
01
1c
1d
But I dont want to filter the row which has 0 in the second column if its not below the row which has 81 in the second column:
Expected output :
01
1c
0
1d
0