Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)
edited by

I have the below string similar to this:

HELLO TEST PACKAGE PARIS1 PROJECT

I got the string from the selecting row and column:

project_name = df[col_pro].values[row_pro]

I also want to get "PARIS" to be in the new column which is 'location_id'

I tried using the split but it was difficult for me to get  "PARIS" only.

How can I do this with python? Thank you

1 Answer

0 votes
by (36.8k points)

I would use the Named groups. Say you have df;

                               text

0  HELLO TEST PACKAGE PARIS1 PROJECT

Using the Named Groups

df.text.str.extract(r'(?P<location_id>PARIS)')

 Improve your knowledge in data science from scratch using Data science online courses

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...