Friday, 15 March 2013

python - Don't know how to solve this error -



python - Don't know how to solve this error -

i reading csv file, editing of values in it, , trying write csv file. when seek execute says stuff in imgur link. i'm not sure why doing this.

http://imgur.com/akxeouk

here excel/csv file:

https://onedrive.live.com/redir?resid=45e225bf1e0acb4%21606)

import csv f = open('project survey.csv') csv_f = csv.reader(f) def encoder(x): row in csv_f: if row[2] == "2018": row[2] = 1.0 elif row[2] == "2017": row[2] = 2.0 elif row[2] == "2016": row[2] = 3.0 print (row) homecoming row new_data = [] row in encoder(csv_f): new_data.append(row) print (new_data) f = open('new_data.csv','wb') output = csv.writer(f) row in new_data: output.writerow([row])

writerow writing sequence(lists or tuples) file not single variable. have given single value 'row' parameter writerow should sequence actually.

try

for row in new_data: output.writerow([row])

or

output.writerow(new_data)

python csv row

No comments:

Post a Comment