Zanam Zanam - 2 months ago 6
Python Question

python array of unicodes to float conversion

I have an array which looks as:

MyArray
array(['1445.98', '1422.64', '1392.93', ..., '2012.21', '1861.19',
'1681.02'], dtype=object)

type(MyArray[0])


I tried:

MyArray.astype(np.float)


Error:

ValueError: could not convert string to float: -


How do I convert MyArray to array of floats instead.

Answer

Maybe convert each memeber individually. Try something like,

map(lambda x: float(x),mydata)