I need to remove a line from a csv with a specific pattern
this is how my csv file looks.
lbm,16730,0
namd,16733,6
namd,16731,2
namd,16732,4
If I want to remove the line with the pattern 16730 and output the rest of the file as it is..
so, the output something like this:
namd,16733,6
namd,16731,2
namd,16732,4
how do I do that?
here is a small script I wrote with the help of some files on the internet
def delete_line(dello):
opener = open(input_csv, 'rb')
dataset = csv.reader(opener, delimiter=',')
output = []
for line in dataset:
if 'dello' == line[1]:
print line[1]
#i dont know how to strip it here
output.append(line)
opener.close()
fn = input_csv
f = open(fn,'w')
f.writelines(output)
f.close()
any hints where I am going wrong?
If you need python, then use this:
Input:
Output:
Note: this will remove all the entries matching the string.
Update
Modifying your code:
If you need to strip out an entry, you can use
dataset.pop(index).