I have a csv file dl.dropboxusercontent.com/s/tb4yc3lm3gg3j22/out.csv and I am trying to replace the last empty column with some calculated values and writing the output in another csv file. My file is getting overwritten in the sense that in the output csv i am getting only the last line of the input csv file with the required header. Can you please help me point out the mistake as why it is getting overwritten on one line and I am not getting the whole data in the output csv.
def read():
for file in os.listdir("./"):
if file.endswith('.csv'):
fNameFull = os.path.basename(file)
inputFileName = os.path.splitext(file)[0]
with open(fNameFull, "rb") as infile, open(inputFileName + '-out.csv', "w") as outfile:
r = csv.DictReader(infile)
w = csv.DictWriter(outfile, r.fieldnames)
w.writeheader()
for row in r:
#print row
if row["r9"]=='':
row["r9"] = "somevalue"
w.writerow(row)