用Python编写的CSV文件在每一行之间都有空行。import csvwith open('thefile.csv', 'rb') as f:
data = list(csv.reader(f))
import collections
counter = collections.defaultdict(int)
for row in data:
counter[row[10]] += 1with 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时,在每个记录之后都会有一个额外的空行!有没有办法使它不加额外的空行?
3 回答
子衿沉夜
TA贡献1828条经验 获得超3个赞
\r\n
\n
\r\n
\r\r\n
.
lineterminator
三国纷争
TA贡献1804条经验 获得超7个赞
with open('/pythonwork/thefile_subset11.csv', 'w', newline='') as outfile:
添加回答
举报
0/150
提交
取消