Answer the question
In order to leave comments, you need to log in
How to find lines other than the main ones?
I have a CSV file with n columns. In column 4 there are values that need to be replaced with keys, but there are values with errors, i.e. base values: 1, 1.1, 1.1.1, 1.2.1, 1.2.2, errors: 1.; 1.1.; 1.1.1.; 1.1; 1.1 (with spaces); 1.2.2.; 1.2.2; 1.2.2.. How to find all errors and fix them? According to the idea ... errors can be very different.
with open("csv_f.csv", 'rb') as F1, open("Res.csv", 'wb') as f2:
reader = csv.reader(F1, delimiter=',', quotechar='"')
writer = csv.writer(f2, delimiter=',', quotechar='"')
val1 = ['1','1.1','1.1.1','1.2.1','1.2.2']
key=['key_1']
for line in reader:
for index,value in enumerate(line):
If value in val1:
line[4]=key[0]
writer.writerow(line)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question