我现在正在使用 python 编写心电图信号,但遇到此错误,我不知道如何解决它。
ValueError: could not convert string to float: '-0,274697\n'
最佳答案
好的,您正在尝试将带有 ,
的字符串转换为 float 。
在 Python 中,号码中不能有逗号,仅支持 .
。要转换它,您可以使用这些行
datei= open(dateiname,'r')
dateistr = datei.readline().replace(',','.') #replacing comma with .
dateistr = dateistr.replace('#','') # replacing # with blank
dateistr = dateistr.strip('\n') #remove the new line character at the end
return float(dateistr)
关于python - 值错误: could not convert string to float: '-0,274697\n' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42013867/