I have to numpy string array which look like this:
[['0', '', '12.12', '140.65', '', ''],
['3', '', '10.45', '154.45', '', ''],
['5', '', '15.65', '184.74', '', '']]
What I need to do is to replace the empty cells with a number in order to convert it into a float array. I can't just delete the columns because in some cases the empty cells are filled. I tried this:
data = np.char.replace(data, '','0').astype(np.float64)
But this will just put a 0 everywhere between all characters which ends up in this:
[[0, 0, 1020.0102, 104000.0605, 0, 0],
[30, 0, 1000.0405, 105040.0405, 0, 0],
[50, 0, 1050.0605, 108040.0704, 0, 0]]
I can't figure out why python does that? I searched via google but couldn't find a good explanation for numpy.char.replace. Can anyone explain to me how it works?