From Tuple To Integer Using Csv Files
I'm having a little problem using csv.reader. I have two files: FileA corresponds to 9 geographical coordinates (x (column1) and y(column2), with no headers). The file is save from
Solution 1:
a[b, c]
indexes a
with the tuple (b, c)
. You need to think hard about what you really want to do at the specific lines where you do this.
Solution 2:
You are try to access list with the tuple. Please try file[sequence[i]: 1] = coordinates[i:1]
.
Solution 3:
For example
test.csv:
'a,b,c,d,f,g'
In [2]: import csv
In [3]: spamReader = csv.reader(open('test.csv', 'rb'), delimiter=',', quotechar='|')
In [4]: spamReader
Out[4]: <_csv.reader object at 0x1e34ec0>
In [5]: spamReader.next()
Out[5]: ['a', 'b', 'c', 'd', 'f', 'g']
the csv.reader returns an object is an iterator, not a tuple or list. Hence FileA should be an iterator (you can't directly convert it to list)
Solution 4:
You are accessing lists incorrectly: you cannot access two-dimensional lists using a comma, as you would in R or MATLAB. Please look over Python listsvery thoroughly.
Based on your code, I think this should accomplish what you are trying to do:
import csv
FileA = csv.reader(open(‘C:/testing/FileA.csv’,'rb'),delimeter',')
FileB = csv.reader(open(‘C:/testing/FileB.csv’,'rb'),delimeter',')
FileC = [0] * 10for lineA, lineB inzip(FileA, FileB):
FileC[int(lineB[0])] = lineA
print FileC
Post a Comment for "From Tuple To Integer Using Csv Files"