Open abbyt99 opened 6 years ago
The common variable is "State". In the f data, "State" is in row 18 and if the f2 data set, "State" is in row 0
Please include the error message when posting bugs.
The error message will likely tell you which line of code produced the error. If you print out your variables in the line prior, you may gain some insights as to what is going on.
IndexError Traceback (most recent call last)
The error message is saying that the list represented by row
does not have at least 19 elements. This could be a special instance of row
that does not have enough elements or all instances of row
. I recommend putting a print row
just before the if statement in line 15 to see what the specific row that is throwing the error looks like.
f=open(filename, 'r').read().splitlines() f_data=[] for line in f: f_data.append(line.split(','))
f2=open(filename2, 'r').read().splitlines() f2_data={} for line in f2: l=line.split(',')
print row
data=[] for row in f_data: if row[0] not in f2_data: print row else: data.append(row + f2_data[row[0]])
Here is the code with us printing the row. When we printed the row, the last row of our f_data came up. I don't know what that means. I do not know how to fix the row error
We have read in both data sets, but when we tried to merge then it said that the list index is out of range. This is the code that we used to try to merge the sets. `f2_data={}
for line in f2: l=line.split(',') if l[0] in f2_data: print l print f2_data[l[0]] f2_data[l[0]]=l
print f2_data
data=[] for row in f_data: if row[18] not in f2_data: print row else: data.append(row+f2_data[row[0]])
print data`