Converting string series to float list in python

Try a list comprehension:

s="5.2 5.6 5.3"
floats = [float(x) for x in s.split()]

In Python 2.x it can also be done with map:

floats = map(float, s.split())

Note that in Python 3.x the second version returns a map object rather than a list. If you need a list you can convert it to a list with a call to list, or just use the list comprehension approach instead.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)