• newline
  • csv

The way Python handles newlines on Windows can result in blank lines appearing between rows when using csv.writer.

In Python 2, opening the file in binary mode disables universal newlines and the data is written properly.

with open('/pythonwork/thefile_subset11.csv', 'wb') as outfile:
    writer = csv.writer(outfile)

In Python 3, leave the file in text mode, since you’re writing text, but disable universal newlines.

with open('/pythonwork/thefile_subset11.csv', 'w', newline='') as outfile:
    writer = csv.writer(outfile)