Home > OS >  ValueError: could not convert string to float: 's'
ValueError: could not convert string to float: 's'

Time:08-05

I am trying to use z scores to reguralize the data and remove the null values out of kaggle songs.

Here is my code:

  # Then we calculate the standard deviation
  crab = 0
  
  for dog in column:
      crab  = (float(dog) - average)**2
  crab /= n
  crab = math.sqrt(crab)
  # Then when we update the values
# for column in data.columns:
#     s = sum(column) / len(column)
#     u = for standard in columnlength(column)
#     for elements in column:
# print(data.shape) 

The bottom part is what I am having trouble with, and here is the link to my code and data: https://colab.research.google.com/drive/1u5_lDgXCQOyt_1HYxUERWtgOtBNNPwdY?usp=sharing

Error: ValueError: could not convert string to float: 's'

CodePudding user response:

Your issue is here

for dog in column:
  crab  = (dog - average)**2

"average" is of type float and "dog" is of type string. Try casting dog to a float like this and see if it works:

for dog in column:
  crab  = (float(dog) - average)**2
  • Related