Hey Guys
Im trying to learn python by doing some csv manipulation by looping through 1 CSV then searching another for the matches then picking up a row then paste the matching row back into the first
Can anyone point me in the right direction to whats going wrong? I think its breaking at line 19?
Any help would be appreciated!
Im trying to learn python by doing some csv manipulation by looping through 1 CSV then searching another for the matches then picking up a row then paste the matching row back into the first
Can anyone point me in the right direction to whats going wrong? I think its breaking at line 19?
Any help would be appreciated!
Code:
import csv
madison = open("madison.csv","r", encoding='utf8')
csvReader = csv.reader(madison)
price = {}
for row in csvReader:
if row[12].strip() not in price:
price[row[12].strip()] = row[4].strip()
madison.close()
products = open("products.csv","r", encoding='utf8')
csvReader = csv.reader(products)
products_data = []
for row in csvReader:
products_data.append(row)
products.close()
for row in products_data:
if(row[13].strip() in price):
row[23] = price[row[13].strip()]
products.close()
products_file = open("products.csv","w",newline='',encoding='utf8')
csvWriter = csv.writer(products_file)
for row in products_data:
csvWriter.writerow(row)
products_file.close()