I wrote the following code to transform the data in a csv file and write to another csv file:
fp = r'C:\data\input.csv'
fpw = r'C:\data\output.csv'
with open(fp, 'rb') as input, open(fpw, 'wb') as output:
for row in csv.reader(input):
stop = row # find a particular field
extr = re.search(r"\[([A-Za-z0-9_]+)\]", stop) # extract value enclosed by brackets in that field
stop_id = str(extr.group(1))
row = stop_id # replace the original field with the extracted value
repl_row = ','.join(row) + '\n'
output.write(repl_row) # write the tweaked row to another csv file
The code worked half way through the file and stopped due to an error raised, that said 'for row in csv.reader, line contains NULL byte'. I want to skip this error and proceed. Despite the except statement, it still stopped. Does anyone know how to solve this issue?
Much appreciate, Sui