numpy.float64 object is not iterable…but I’m NOT trying to

It looks like you’re trying to extend a list with a scalar float variable. The argument to extend must be an iterable (i.e. not a float). From your first bit of code it looks like means[i][j][k] returns a float,

print means['716353'][0][0] #OUT : 76.6818181818

The problem is here,

temp.extend(means[row['ID']][i][0])

If you expect that means[i][j][k] will always be a single value and not a list you can use append instead of extend.

temp.append( means[row['ID']][i][0] )

An example to show the difference,

l = [i for i in range(10)]
l.extend( 99.0 )
TypeError: 'float' object is not iterable

this doesn’t work b/c a float is not iterable

l.extend( [99.0] )
print l
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 99.0]

this works b/c a list is iterable (even a one element list)

l.append( 101.0 )
print l
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 99.0, 101.0]

append does work with a non-iterable (e.g. a float)

Leave a Comment