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

Question:

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’

Asked By: Mark Jacobs

||

Answers:

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
Answered By: JRose
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.