I created a program that search and replaces over an entire csv file but I need to make so it is column specific. Is there a way to only search via a column. Here is my code, I am pretty new to python so I apologize if this is an easy fix.
import csv
ifile = open('testbook.csv', 'rb')
reader = csv.reader(ifile,delimiter='\t')
ofile = open('output.csv', 'wb')
writer = csv.writer(ofile, delimiter='\t')
findL = ['Australia', 'Mexico', 'United States', 'hob']
replaceL = ['Kangaroo', 'Spider Monkey', 'Eagle', 'Test']
rep = dict(zip(findL, replaceL))
def findReplace(find, replace):
s = ifile.read()
for item, replacement in zip(findL, replaceL):
s = s.replace(item, replacement)
ofile.write(s)
for item in findL:
findReplace(item, rep[item])
ifile.close()
ofile.close()