0

I have got a dataframe looks like this:

  1. 12000 pa
  2. 13000 per annum
  3. 25000 pa
  4. 34000 per annum

I need to update all four cells into int only, so:

  1. 12000
  2. 13000
  3. 25000
  4. 34000

What is the quickest method for doing this?

PYDater
  • 17
  • 2
  • 1
    Does this answer your question? [Pandas: how to change all the values of a column?](https://stackoverflow.com/questions/12604909/pandas-how-to-change-all-the-values-of-a-column) – Tomerikoo Nov 15 '20 at 10:03

1 Answers1

0

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)

Elzar
  • 16