Apr-17-2019, 08:27 AM
After reviewed few recommend similar topic about comparing value, there is not much help for me.
car.csv tittle1,tittle2 bmw,2000 mercedes,2000 toyota,1000 honda,1500 geely,500 price.csv ori_price1,new_price2 2000,5000 1000,2500The result should looks like
tittle1,tittle2 bmw,5000 mercedes,5000 toyota,2500 honda,1500 geely,500I did try the code below
import csv with open('car.csv', 'r') as csv_file, open('price.csv', 'r', newline='') as csv_file2 \ ,open('result.csv', 'w', newline='') as new_file: csv_reader = csv.DictReader(csv_file) csv_reader2 = csv.DictReader(csv_file2) csv_writer = csv.writer(new_file) csv_writer.writerow([ 'tittle1', 'title2']) for row1,row2 in zip(csv_reader,csv_reader2): csv_writer.writerow([row1['tittle1'],row1['tittle2'],row2['new_price2']])The code only replaces the whole column without comparing the value.