'Ending up with an empty csv file after try to add required rows from csv?

I try to implement simple logic to required rows from original data. I am ending up with an empty csv file. I don't know what's wrong with my code.

Sample dataset is here:

sample code is here:

with open ('tracksample.csv','r') as inp, open('final.csv','w') as out:
    writer = csv.writer(out)
    for row in csv.reader(inp):
        if (row[3] == "0" and row[4] == "0"):
            writer.writerows(row) 

Any leads will be appreciated and advance thanks.



Solution 1:[1]

import csv
p=open('final.csv','w')
writer = csv.writer(p)
f=open('sample.csv','r')
for row in csv.reader(f):
    if row==[]:
        continue
    print(row)
    if (row[3] == "0" and row[4] =="0"):
            print(row)
            writer.writerow(row) 
    

p.close()
f.close()

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