1

I have a dataframe which looks like this.

COURSE_ID
EX-AAB-5S-102345
EX-A45-5F-143567
INC-AAB-WW-104514
INC-AAB-DE-567431

What i am trying is to create a new column COURSE where i will only have the 6digit numerical filed

COURSE_ID.            COURSE
EX-AAB-5S-102345.     102345
EX-A45-5F-143567.     143567
INC-AAB-WW-104514.    104514
INC-AAB-DE-567431.    567431
anky
  • 74,114
  • 11
  • 41
  • 70
sayan nandi
  • 83
  • 1
  • 6
  • Does this answer your question ? [Pandas Extract Number from String](https://stackoverflow.com/questions/37683558/pandas-extract-number-from-string) – anky Apr 25 '21 at 12:44
  • `df['COURSE']=df['COURSE_ID.'].str.split('-').str[4]`? – Anurag Dabas Apr 25 '21 at 12:45

1 Answers1

1

Using str.extract:

df["COURSE"] = df["COURSE_ID"].str.extract(r'(\d+)$')
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360