Hi, I have this array of strings but I can't convert it in an array of floats, I think because of the comma. So there is a way to convert comma in dot or convert directly arrays of strings in an array of floats?
CodePudding user response:
We can try replacing the comma with period and then casting:
df["col"] = df["col"].str.replace(',', '.', regex=False).astype(float)
CodePudding user response:
Assuming you're dealing with a 1D array named arr
:
new_arr = np.array([float(elem.replace(',', '.')) for elem in arr])
Or:
new_arr = np.char.replace(arr, ',', '.').astype(float)