When I tried to do some calculation between two columns (like division), I get an error: column_ratio[x]=(float(column1[y]))/(float(column2[z])) TypeError: tuple indices must be integers, not str
. Could someone help me to solve this problem?
from itertools import izip_longest
import csv
with open(r"C:\Users\a.txt", 'rb') as csv1,\open(r"C:\Users\b.txt", 'rb') as csv2, \open(r"C:\Users\c.txt", 'rb') as csv3, \open(r"C:\Users\out.txt", 'w') as out:spam1 = csv.reader(csv1, delimiter=',')spam2 = csv.reader(csv2, delimiter=',')spam3= csv.reader(csv3, delimiter=',')column1=list(izip_longest(*spam1))[-1]column2=list(izip_longest(*spam2))[-1]column3=list(izip_longest(*spam3))[-1]column_ratio=[]for x,y,z in izip_longest(column_ratio, column1, column2):column_ratio[x]=(float(column1[y]))/(float(column2[z]))for i,j,m,n,x in izip_longest(spam1,column1, column2, column3, column_ratio):out.write(','.join(i)+','+j+','+m+','+n+','+x+'\n')