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?
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=',')
There are locales that use '.' as decimal separator and ',' as thousands-separator. There are also locales that use ',' as decimal separator and '.' as thousands-separator.
Doing a plain string-replace will get you in all sorts of trouble. You need to
import locale
then specify which locale you want to use, e.g.
locale.setlocale(locale.LC_NUMERIC, 'german')
and then you can parse the string using
locale.atof('1.337,3')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With