Skip to content
Advertisement

Create and fill a DataFrame column based on conditions

I have a DataFrame and I need to create a new column and fill the values acording to how many words in a list of words are found in a text. I’m trying de code below:

JavaScript

This code actually create a new column, but fill all the rows with the last ‘count_found_words’ of the loop.

is there a right way to do this?

Advertisement

Answer

JavaScript

This forms the regex b(water|pasta|black|magic|glasses|school|book)b that looks for any of the words in the list. Finds all it could and reports the number of matches via .len.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement