1

I have a dataset, in which the column looks like this:

col
AMPCO Impact Socket
MEGGAR HARLEY Impact Socket

Is there any way where I can be able to extract AMPCO, MEGGAR HARLEY? Even if I can get MEGGAR from second sentence, that would also work.

I tried res = list(filter(lambda c: c.isupper(), test_str[:1])) and many other ways but I am not getting what I want

jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252

1 Answers1

0

Use Series.str.findall with Series.str.join:

df['new'] = df['col'].str.findall(r'\b[A-Z]+\b').str.join(' ')
print (df)
                               col            new
0              AMPCO Impact Socket          AMPCO
1      MEGGAR HARLEY Impact Socket  MEGGAR HARLEY
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252