将字符串更改为在字符串中用(“”)浮动

2021-06-14 23:43:34 发布

您现在位置:Python中文网/ 问答频道 /正文

好的,我在文件里有这样的字符串

"0.9986130595207214","16.923500061035156","16.477115631103516","245.2451171875","107.35090637207031","118.8438720703125","254.64633178710938","255.2373046875","264.1331481933594","28.91413116455078"

我有多排。你知道吗

如何将数据更改为浮点数或数字,我遇到了问题,因为项目变成了“0.9986130595207214”。你知道吗

我写的代码是:

import numpy as np
data = np.loadtxt("data.csv",dtype=str,delimiter=',')
for y in data:
    for x in y:
        print(float(x))

出现错误:

print(float(x)) ValueError: could not convert string to float: '"0.9986130595207214"'

谢谢