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

Python Pandas Extract text between a word and a symbol

I am trying to extract text between a word and a symbol.

Here is the input table.

enter image description here

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

And my expected output is like this.

enter image description here

I do not want to have the word ‘Team:’ and ‘<>’ in the output.

I tried something like this but it keeps the ‘Team:’ and ‘<>’ in the output: data[new col]=data[‘Team’].str.extract(r'(Team:\s[a-zA-Z\s]+<>)

Thank you.

>Solution :

Use regex captured group for str.extract method:

df['Team'].str.extract(r'^Team: ([^<>]+)')

  • [^<>]+ – matches any character except < and > chars
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