ValueError: 无法将字符串转换为浮点数:'62,6'

Sta*_*kov 2 python numpy pandas valueerror

我正在尝试将数据帧转换为 numpy 数组:

dataset = myset.values
X = np.array(dataset[0:,6:68], dtype="float32")
X[0:5,0:]
Run Code Online (Sandbox Code Playgroud)

这是一段数据

这是一个错误:

-----------------------------------------------------------------------

----
ValueError                                Traceback (most recent call last)
<ipython-input-162-4b67608047d1> in <module>()
      1 dataset = myset.values
----> 2 X = np.array(dataset[0:,6:68], dtype="float32")
      3 X[0:5,0:]

ValueError: could not convert string to float: '62,6'
Run Code Online (Sandbox Code Playgroud)

哪里有问题?

jez*_*ael 5

尝试使用到:replace ,.

dataset = myset.replace(',','.', regex=True).values
Run Code Online (Sandbox Code Playgroud)

或使用参数decimalinread_csv转换,.in 浮点数:

dataset = pd.read_csv('file', decimal=',')
Run Code Online (Sandbox Code Playgroud)