I have the following dataframe, df:
name result
AAA 4.5
BBB UNK
CCC less than 2.45
DDD Men > 40: 2.5-3.5
The dtypes of the result column is dtype('O')
I need to extract the float values and filter them with a particular threshold.
I tried the following script to extract the values and change them to float:
df['result'] = df['result'].str.extract(r'(\d+.\d+)').astype('float')
However, I'm not sure if I'm getting the right output, especially when the value has a range 2.5-3.5. In this scenario, I want the max value, i.e. 3.5.
Desired output:
name result
AAA 4.5
CCC 2.45
DDD 3.5
What would be the smartest way of doing it? Any suggestions would be appreciated. Thanks!