相关疑难解决方法(0)

用Python编写的CSV文件在每行之间都有空行

import csv

with open('thefile.csv', 'rb') as f:
  data = list(csv.reader(f))
  import collections
  counter = collections.defaultdict(int)

  for row in data:
        counter[row[10]] += 1


with open('/pythonwork/thefile_subset11.csv', 'w') as outfile:
    writer = csv.writer(outfile)
    for row in data:
        if counter[row[10]] >= 504:
           writer.writerow(row)
Run Code Online (Sandbox Code Playgroud)

此代码读取thefile.csv,进行更改并将结果写入thefile_subset1.

但是,当我在Microsoft Excel中打开生成的csv时,每条记录后都会有一个额外的空白行!

有没有办法让它没有多余的空白?

python windows csv

394
推荐指数
7
解决办法
24万
查看次数

标签 统计

csv ×1

python ×1

windows ×1