Skip to content
Advertisement

Find value from string using the characters from list Using Python

I have been working on an Excel sheet using python, where i have to extract only the specific value from the column, using an list with set of charaters.

Need to check every character from the column check with the list, If it matches need to return the matched value into the dataframe which can be used for further analysis.

Input Data :

JavaScript

Expected Output:

JavaScript

Code Snippet:

JavaScript

But It didn’t worked Also Tried :

JavaScript

Advertisement

Answer

You can use

JavaScript

Here, Series.str.findall returns all matches found in each cell in the country_list column, and the pattern, that looks like (?i)b(?:Country1|Country2|...)b, matches

  • (?i) – case insensitive inline modifier option
  • b – a word boundary
  • (?:Country1|Country2|...) – a list of countries
  • b – a word boundary
Advertisement