我有很大的CSV文件,216961行:使用python,如果特定字符出現在這行中,如何刪除csv文件中的整行?
9808,54,43,59,999,17,10,59,999,-1,0,0
9809,54,43,59,999,17,12,0,-1,0,0
9810,54,43,59,999,17,13,0,001,-1,0,0
9811,54,43,59,999,17,13,59,999,-1,0,0
9812,54,43,59,999,17,15,0,-1,0,0
9813,54,43,59,999,17,16,0,001,0,0,0
9814,54,43,59,999,17,16,59,999,0,0,0
9815,54,43,59,999,17,18,0,0,0,0
9816,54,43,59,999,17,19,0,001,0,0,0
9817,54,43,59,999,17,19,59,999,0,0,0
9818,54,43,59,999,17,21,0,0,0,0
9819,54,43,59,999,17,22,0,001,0,0,0
9820,54,43,59,999,17,22,59,999,0,0,0
我需要篩該文件並刪除所有行其中-1目前,約有6900線, 所以我想問一下您的幫助
我嘗試:
import csv
reader = csv.reader(open("file.csv", "rb"), delimiter=',')
for line in reader:
match = line[7]
if match not in '-1':
print line
但-1並不總是在行[7]
請發佈您試過的代碼。請詢問您嘗試過的代碼的具體問題。到目前爲止,這只是使用'csv'模塊的幾行Python。請發佈一些您嘗試過的代碼無效的代碼,以便我們知道您需要哪種幫助。 –