I am fairly inexperienced with the csv module in Python and was wondering if anyone could give any pointers. I have been looking through many other questions regarding this question but have come up with no answers for mine.
All I want to do is alter values, in which case it would be "n/a" and replace it with 0 in my csv file. These n/a values are within all columns so I can't pinpoint it to one specific column.
This is my code so far:
with open("MyCSV.csv","rb") as infile,open("Write.csv","wb") as outfile:
reader= csv.reader(infile)
writer= csv.writer(outfile)
conversion= set('(n/a)')
for row in reader:
newrow=[''.join('0' if c in conversion else c for c in entry)for entry in row]
writer.writerow(newrow)
The issue I have come across in my result is that any a or n is transformed to a 0. This is obviously because it is being read that every 'n' or 'a' should be converted.
Thanks for any help someone can give.