Reputation: 255
I have a csv file named test.csv . It contains certain rows with string for instance "Blue". How can I create a new csv file without the rows containing the string "Blue".
N.B Came to this as the find and replace method doesn't remedy the situation.
Upvotes: 0
Views: 559
Reputation: 174696
You may use not in
with open(file) as f, open(outfile, 'w') as w:
for line in f:
if 'Blue' not in line:
w.write(line)
or
with open('infile') as f, open('outfile') as w:
for line in f:
for i in line.split(','):
if 'Blue' in i:
break
else:
w.write(line)
Upvotes: 1