Python - invalid literal for float ()

2

I have an array that looks like this

training_set = [['03/11/2017' '16,94']
 ['01/11/2017' '16,90']
 ['31/10/2017' '16,77']
 ...

However, I can not manipulate the numbers because they are in the form of string . How do I clean the data and leave it like this

training_set = [['03/11/2017' 16,94]
 ['01/11/2017' 16,90]
 ['31/10/2017' 16,77]
    
asked by anonymous 07.11.2017 / 02:17

1 answer

1

The problem is in the format of its value, such as string . You are using the comma as the decimal separator, but Python uses the dot. That is, to convert to float , your string should be something like '16.94' .

You can, before converting to float , try replacing the comma with the dot:

float('16,94'.replace(',', '.'))
    
07.11.2017 / 02:26