python - 值错误: could not convert string to float: '-0,274697\n'

标签 python

我现在正在使用 python 编写心电图信号,但遇到此错误,我不知道如何解决它。

ValueError: could not convert string to float: '-0,274697\n'

enter image description here

最佳答案

好的,您正在尝试将带有 , 的字符串转换为 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/

相关文章:

python - 使用 cElementTree 从 XML 查找所有节点

python - 如何使用 pandas 的 eval 函数计算两个日期列之间的天数?

python - Sympy:生成具有多个子图的图形

具有不同维度的python卷积

python - 在 Python 中解析 CSV 101

python - 更改新 URL 的 Selenium 驱动程序

python - Pandas:对给定列求和 DataFrame 行

python - 将列表中的大整数值拆分为多个列表中的较小整数

python - 字符编码

python - 如何使用setuptools安装到自定义目录?