I'm trying to convert a string value in a float value after convert it in text, the code is:
Sell = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[starts-with(@class, "
"'section-table-body"
"')]//span[text( "
")='Amazon']//following"
"::div[ "
"2]")))
Sell = Sell.text
Sell = float(Sell)
The error I get is this: ValueError: could not convert string to float: '127,36'
CodePudding user response:
You are getting this error because the value uses comma ,
to denote the decimal values. Python does not understand ,
as decimal seperator and needs to use dot .
instead.
Try this :
Sell = "127,36"
Sell = ".".join(Sell.split(","))
Sell = float(Sell)
print(Sell)
CodePudding user response:
The comma in the string is not identified as a decimal. Try this instead
Sell = "127,36"
Sell = Sell.replace(',', '.')
Sell = float(Sell)