Hi,
I am looping through a csv file using Python to remove header lines, unnecessary columns and trying to replace any blank latitude and longitude coordinate values with a value of (0, 0), these coordinates are in two separate columns. For this replace process I am using a ‘for’ loop and the ‘replace’ method and am indexing (in the case of the csv file I am working with, the index of the two columns are 36 and 37). However, I keep getting a “list index out of range” error message when doing this. Any thoughts to point me in a better direction?
Here's the code:
<pre>
count = 0
for n in range(6):
count = count + 1
line = inFile.readline()
while line:
count = count + 1
line = inFile.readline()
print 'Row', count, 'line info=', line[:72]
lineList = line.split(',')
newList = lineList[:72]
print 'line info =', newList
for item in newList[36]: #-> use "if" statement; for column, if name == "LatitudeNAD83" and
item.replace("", "0")
for item in newList[37]:
item.replace("", "0")
newLine = ','.join(newList)
newLine = newLine + '\n'
formatLine = newLine.replace("/","_")
outFile.write(formatLine)
</pre>
Thanks!
I am looping through a csv file using Python to remove header lines, unnecessary columns and trying to replace any blank latitude and longitude coordinate values with a value of (0, 0), these coordinates are in two separate columns. For this replace process I am using a ‘for’ loop and the ‘replace’ method and am indexing (in the case of the csv file I am working with, the index of the two columns are 36 and 37). However, I keep getting a “list index out of range” error message when doing this. Any thoughts to point me in a better direction?
Here's the code:
<pre>
count = 0
for n in range(6):
count = count + 1
line = inFile.readline()
while line:
count = count + 1
line = inFile.readline()
print 'Row', count, 'line info=', line[:72]
lineList = line.split(',')
newList = lineList[:72]
print 'line info =', newList
for item in newList[36]: #-> use "if" statement; for column, if name == "LatitudeNAD83" and
item.replace("", "0")
for item in newList[37]:
item.replace("", "0")
newLine = ','.join(newList)
newLine = newLine + '\n'
formatLine = newLine.replace("/","_")
outFile.write(formatLine)
</pre>
Thanks!