I have a string similar like this:
JavaScript
x
2
1
HELLO TEST PACKAGE PARIS1 PROJECT
2
I got this string from selecting row and column:
JavaScript
1
2
1
project_name = df[col_pro].values[row_pro]
2
and I want to get the “PARIS” only to be in a new column which is ‘location_id’
I tried to split them, but it was hard for me to get the “PARIS” only.
How can I do this with python? Thank you
Advertisement
Answer
I would use Named groups.
Say you have df
;
JavaScript
1
3
1
text
2
0 HELLO TEST PACKAGE PARIS1 PROJECT
3
Using Named Groups
JavaScript
1
2
1
df.text.str.extract(r'(?P<location_id>PARIS)')
2