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
。
但是,当我在 MicrosoftExcel 中打开生成的 csv 时,每条记录后面都有一个额外的空行!
有没有什么办法不让它多写一行空白?