I have a dataframe :
A B
10.1 33.3
11.2 44.2s
12.3 11.3s
14.2s *
15.4s nan
i want output as
A B
10.1 33.3
11.2 44.2
12.3 11.3
14.2 0
15.4 0
How do I remove these tailing alphabets
I have tried this code
1st approach:
bulb_temp_df['A'].str.extract('(\d)').astype(float)
bulb_temp_df['B'].str.extract('(\d)').astype(float)
2nd approach:
bulb_temp_df['A'] =
bulb_temp_df['A'].astype(str)
bulb_temp_df['A'] =
bulb_temp_df['A'].map(lambda x: x.rstrip('aAbBcC'))
These are not working. They are not removing the tailing s from the columns.
third approach
bulb_temp_df[cols]=bulb_temp_df[cols].apply(lambda x:x.str.extract('(\d+\.\d+)',expand=False)
.astype(float)
.fillna(0))`
All these are not working. The last one removes the tailing s but it converts the values without 's' to zero or nan.