Indexerror While Printing In From Csv
While reading in from a CSV file of two columns and 36 Rows long, I reach line 25 and I have an error thrown. I've checked in the file in two different editors and there isn't a n
Solution 1:
Simply put, you are reading a row that doesn't have at least 2 elements on it. I'm not sure what you want to do with a row that doesn't, I suspect you just want to skip it. Here's an example of how you could do that:
defprintCSV():
f = csv.reader(open("ArticleLocationCache.csv", "rb"))
i = 1print (i)
for row in f:
iflen(row)>=2:
print ("Line", i, row[1])
i = i + 1
Looking at your CSV file, it seems like you might not be parsing it correctly. As an alternative to figure out what's going on, try just printing the whole row out, and then figure out why it's not working as you want, as follows:
defprintCSV():
f = csv.reader(open("ArticleLocationCache.csv", "rb"))
i = 1print (i)
for row in f:
print (row)
print ("Line", i, row[1])
i = i + 1
Post a Comment for "Indexerror While Printing In From Csv"