I'm trying to go through a csv file, validate zip codes and write the city and state to the last column in the csv file.
I managed to get the csv data and get the city and state, but I don't understand how to write the new data to the last column. SO examples like this show how to create a csv, but not work with an existing csv.
here is my code so far:
with open("propertyOutput.csv", "rbw") as fp:
reader = csv.DictReader(fp, skipinitialspace=True)
table = [row for row in reader]
for rows in table:
stringNeed = rows['zip']
if not stringNeed.isdigit():
print"not number" #would like to write this to the column
pass
else:
if not len(stringNeed) == 5:
print"string not 5 long" # would like to write this to the column
else:
x = getCityState(stringNeed)
print x # would like to write this to the column