How to separate floats from strings

You can easily take the value ".25+1" and use its .split() function for both '+' and '-' then just use the first value in the list like so

val = '.25+1'
parts = val.split('+' if '+' in val else '-')
print(parts[0]) #Output is """ .25 """

or, if there are other characters in the string than a + or -, you can create a new string while iterating over each character like this:

val = '.25+1'
newString = ''
for char in val:
    if not char.isdigit() and char != '.': break
    newString += char
print(float(newString)) #Output is """ .25 """

in future, please, use raw text (copy past) not screenshots.


lum = []
f = open('.\\test_big.txt')
lines = f.readlines()

for x in lines:
    data = x.split('\t')

    if '+' in data[5]:
        part01 = data[5].split('+')
        final_value = float(part01[0])

    if '-' in data[5]:
        # one line
        final_value = float(data[5].split('-')[0])

    lum.append(final_value)

print(lum)

Output: [0.25, 0.47, ...]