I have the following dataframe:
df = pd.DataFrame({'name': 'A B C D'.split(),
'result': ['.50', 'text 10', 'text 0.20', '<0.75']})
print(df)
name result
0 A .50
1 B text 10
2 C text 0.20
3 D <0.75
I need to extract the numeric values (float, integer or any digits). I'm trying the following script but not getting the desired output with too many NaN
values:
df['result'] = df['result'].astype(str)
df['result'].str.extract(r'(/\d+\.\d+/)')
Desired output
name result
0 A .50
1 B 10
2 C 0.20
3 D 0.75
What would be the smartest way of doing it? Any suggestions would be appreciated. Thanks!