How to convert a string series to a list of floats in Python

Converting a string series to a list of floats results in a list containing each float represented in the string. For example, converting “1.2 2.3 3.4” to a list of floats results in [1.2, 2.3, 3.4].

Solution for How to convert a string series to a list of floats in Python : You can use str.split() to convert a string series to a list of floats Use str.split() to create a list of items separated by whitespace in the string. Create a for-loop to iterate through each item in this list. Use float(item) to convert each item to a float. Call list.append(object) with object as the converted float to append it to a new list.

Use a list comprehension for a more compact implementation.

string_series = "1.2 2.3 3.4"


how-to-convert-a-string-series-to-a-list-of-floats-in-python