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)
该代码读取thefile.csv
,进行更改并将结果写入thefile_subset1
。
但是,当我在Microsoft Excel中打开生成的csv时,每条记录后都有一个额外的空白行!
有没有办法使它不放在多余的空白行?