I would like to make column 2 in the csv file to be all lowercase and removing all the punctuation and save the file. How can i do that?
import re
import csv
with open('Cold.csv', 'rb') as f_input1:
with open('outing.csv', 'wb') as f_output:
reader = csv.reader(f_input1)
writer = csv.writer(f_output)
for row in reader:
row[1] = re.sub('[^a-z0-9]+', ' ', str(row[1].lower()))
writer.writerow(row)
f_input1.close()
How do i add :
re.sub('[^A-Za-z0-9]+', ' ', str(row))
filewriter.writerow([new_row.lower()])
or .lower in this code?
f_input1.close()is not required when using awithstatement here. Also you would need to indent yourforloop to the same level as yourreaderandwriterlines.