I have a seemingly simple task with a .CSV file. I need to replace all white space with 0's for two specific columns (37, 38). I've tried the following code:
import csv
with open("C:/Temp/whiteSpace.csv", "rb") as infile, open("C:/Temp/repaired_test.csv", "wb") as outfile:
reader = csv.reader(infile)
writer = csv.writer(outfile)
for row in reader:
row[37] = row[37].replace(' ', '0')
writer.writerow(row)
print row[37]
However, this simply writes the "whiteSpace.csv" over to "repaired_test.csv" with out editing anything.
I've found plenty on stripping whitespace (strip white spaces from file csv) but I'm not able to connect the dots and make my code work.
Sorry for the redundant question, and thank you in advance.