0

I have a df with a one specific column like this:

var
100 asc
200 asc
150 asc
75  asc

I want to remove asc and retain as number so to get

var
100
200
150
75

Running

number =df['var'].replace('\asc',regex=True)

Yet nothing happens resulting df is exactly the same as the original one, yet no error are shown...

Any ideas?

EGM8686
  • 1,492
  • 1
  • 11
  • 22
  • 1
    Does this answer your question? [Remove unwanted parts from strings in a column](https://stackoverflow.com/questions/13682044/remove-unwanted-parts-from-strings-in-a-column) – huy Apr 08 '20 at 03:08
  • `df['var'].str.extract('(\d+)',expand=False)` – anky Apr 08 '20 at 03:10

1 Answers1

3

Let us try

df['var'] = df['var'].str.strip(' asc')
anky
  • 74,114
  • 11
  • 41
  • 70
BENY
  • 317,841
  • 20
  • 164
  • 234