所以我在处理一个.csv文件,发现在给定数据中,事情的格式不正确,应该是

问题描述

我想以一种方式清除数据,如果某行超出某些列,则应将其删除

enter image description here

解决方法

下面的代码可能有帮助。

number_of_column=3
with open("test.csv","r") as f:
    with open("out.csv","w") as f1:
        line=f.readline()
        while line:
            if len(line.split(","))<=number_of_column:
                f1.write(line)
            line=f.readline()