-1

How can I use the csv module to remove all rows where any of the column values is missing? I my case I have two columns a and b, so if I have a value on a but nothing on b, that row should be removed. How an I achieve this?

Mikael Ken
  • 41
  • 1
  • 10

1 Answers1

2

Try this:

with open(in_filename) as infile:
    with open(out_filename, 'w') as outfile:
        reader = csv.reader(infile)
        writer = csv.writer(outfile)
        writer.writerows(filter(all, reader))
Alex Hall
  • 34,833
  • 5
  • 57
  • 89