I have a question here:
Write a function named
computed_columnthat takes a string as a parameter representing the name of a CSV file with 5 columns in the format<string>,<int>,<int>,<int>,<int>and writes a file namedcreation.csvcontaining all the data from the input file but with a sixth column containing the sum of the values from the third and second columns.
This is what I tried:
import csv
def computed_column(csvfile):
with open(csvfile,newline='') as f:
with open('creation.csv','w',newline='') as f2:
y=[]
writer = csv.writer(f2)
rows = csv.reader(f)
for row in rows:
for i in range(0,len(row[1])):
y.append(int(row[1][i]) + int(row[2][i]))
writer.writerow(row+y)
It writes the original file correctly but gives me wrong output for the sixth column that is to be written.