I am throughly confused as I confirmed that the variable I am trying to convert to a float is indeed a string (I will show my log here):
>>> print ratingXf
'1'
>>> print type(ratingXf)
<type 'str'>
>>> ratingX = float(ratingXf)
ValueError: could not convert string to float: '1'
And I calculate it as follows:
rateX, rateY= v.split(',')
ratingXf = (rateX[1:])
ratingX = float(ratingXf)
And when I try to convert the string to an integer, I get the following error:
ValueError: invalid literal for int() with base 10: "'1'"
Seems this should be straightforward. But I do not understand why I am getting this error. Can anyone spot the problem?
Thanks!
You have a nested string i.e.
ratingX = "'1'"
.For your starting point of
values = ["('1', '1')", "('1', '1')"]
I suggest getting it into the format you want first: