I have got a dataframe looks like this:
- 12000 pa
- 13000 per annum
- 25000 pa
- 34000 per annum
I need to update all four cells into int only, so:
- 12000
- 13000
- 25000
- 34000
What is the quickest method for doing this?
I have got a dataframe looks like this:
I need to update all four cells into int only, so:
What is the quickest method for doing this?
One of the possible solutions:
df["price_int"] = df["price"].apply(lambda value: int(value.split(" ")[0]))
Or you can use Regex (more robust):
df["price_int"] = df["price"].str.extract(r'(^[0-9]+)').astype(int)