I have been looking to remove all the non numerical character, and convert the same to float type, But whenever any String character comes up , it gives the Error as "ValueError: could not convert string to float"
Please suggest how to resolve it .
Input File
col1 col2
122.45 NaN
Ninety Five 3585/-
9987 178@#?
225 Nine 1983.86
Twelve 7363*
Output File
col1 col2
122.45 NaN
NaN 3585
9987 178
225 1983.86
NaN 7363
Code i am using :
df[['col1','col2']] = df[['col1','col2']].replace('([^\d/.])', '', regex=True).astype(float)
Getting the Error:
ValueError: could not convert string to float
'[^\d\.]'and add.replace('', np.nan)like so:df[['col1','col2']].replace('([^\d\.])', '', regex=True).replace('',np.nan).astype(float)replace?