Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to extract last word from a column of a pandas dataframe

My pandas df column looks like this:-

Col1


Closed

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Closed Captives

Closed Captives Blank

Closed Sync

Open

Open Captives

Open Captives Blank

Open Captives Blank Book

Open Sync

Open Sync Candle


My output should be:-

Col1


Closed

Captives

Blank

Sync

Open

Captives

Blank

Book

Sync

Candle

I want this to be done using pandas. Please help me

>Solution :

Edit: After looking at your comment that there are + between words.

You can use .apply() and split each row by + to get the last word:

df['Col1'] = df['Col1'].apply(lambda x: x.split('+')[-1])

Output:

       Col1
0    Closed
1  Captives
2     Blank
3      Sync
4      Open
5  Captives
6     Blank
7      Book
8      Sync
9    Candle
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading