Try to search your question here, if you can't find : Ask Any Question Now ?

Extract prefix from string in dataframe column where exists in a list

HomeCategory: stackoverflowExtract prefix from string in dataframe column where exists in a list
craig asked 2 weeks ago

Looking for some help.
I have a pandas dataframe column and I want to extract the prefix where such prefix exists in a separate list.

pr_list = ['1 FO-','2 IA-']

Column in df is like

PartNumber     
ABC
DEF
1 FO-BLABLA
2 IA-EXAMPLE

What I am looking for is to extract the prefix where present, put in a new column and leave the rest of the string in the original column.

PartNumber   Prefix
ABC          
DEF
BLABLA       1 FO-
EXAMPLE      2 IA-

Have tried some things like str.startswith but a bit of a python novice and wasn’t able to get it to work.

much appreciated

1 Answers
Best Answer
Matthias answered 2 weeks ago
Your Answer

17 + 18 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com