python删除csv某一行,使用python,如何删除csv文件中的整行如果该行中存在特定字符?...

I have large csv file, 216961 lines:

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

I need to sieve the file and remove all lines where -1 is present, about 6900 lines,

so I would like to ask for Your help

my attempt:

import csv

reader = csv.reader(open("file.csv", "rb"), delimiter=',')

for line in reader:

match = line[7]

if match not in '-1':

print line

but -1 is not always at line[7]

解决方案

Try this approach.

import csv

reader = csv.reader(open("file.csv", "rb"), delimiter=',')

for line in reader:

if "-1" not in line:

print line

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值