I am trying to clean a column from a pandas dataframe. I have tried to convert an object of type object to int64:
df2['Pts'] = df2['Pts'].astype(int)
But it won't let me because there is a text string in these fields, they are all numeric but in some cases it appears like this: 55[a] or 55[b]
I have tried to remove those text strings that appear at the end of the numbers to be able to convert it, but it is not possible for me.
df2.replace(['[a]', '[b]'], ['', ''])
Could someone suggest me an idea so that those text strings do not appear inside my int values to be able to operate with said data. Thank you very much in advance. All the best
You can do it in many different ways. I propose several:
with regex
with extract
Note: doing it this way you will only have the first string of numbers that appear consecutively
With a lambda +
isdigit