Home > database >  ValueError: could not convert string to float: ' '
ValueError: could not convert string to float: ' '

Time:02-18

ValueError: could not convert string to float: ' ' I got this error after fill all missing values by mean method and Divided the data into X independent Y dependent And in appied Extra teee for features selection i got this message

CodePudding user response:

Probably, you are trying to convert an empty string into a float.

You may not explicitly do this but some of your calculations in your code may results in an empty string.

  1. First find the code that sets an empty string to the variable that you're trying to convert into a float.
  2. Next, fix the code to set the value 0 instead of an empty string to that variable

Unless you share your code that makes this error, its very difficult for anyone to give precise answer to this question. Try to update this question with the code. Then it will be easy to answer this question.

CodePudding user response:

You need to make sure that your string is actually in float format, or catch the error:

try:
  float(myString)
except ValueError as e:
  # do something
  • Related