tags:

views:

53

answers:

1
  for row in c:
    c1.append(row[0:13])

  for row in c1:
    row.append(float(row[13])/100)
    row.append(float(row[12])/float(row[13])/100)
    row.append(math.log10(float(row[12])))

c contains a csv file with many rows and columns c1 is a subset of c containing only the first 14 elements

i am getting IndexError: list index out of range on row.append(float(row[13])/100)

does anyone know what i am doing wrong?

+1  A: 

The rows in c1 don't actually contain 14 elements, they contain 13.

The second index in a slice is non-inclusive. When you append row[0:13] to c1 you are appending from element 0 to the element before 13. Hence, there are only 13 elements.

This is why you get IndexError: list index out of range on row.append(float(row[13])/100). row[13] is an attempt to access a non-existent 14th element.

Steven Rumbalski
It's also worth noting that if there are less than 13 elements in the initial array, `c1.append(row[0:13])` won't throw an error either.
job