Search code examples
pythonpandasnumpyvalueerror

ValueError: could not convert string to float: '62,6'


I am trying to convert dataframe to numpy array:

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

Here is a piece of the data

Here is an error:

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

----
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'

Where is a problem?


Solution

  • Try use replace , to .:

    dataset = myset.replace(',','.', regex=True).values
    

    Or use parameter decimal in read_csv for convert , to . in floats:

    dataset = pd.read_csv('file', decimal=',')