Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

py - count if a word is present in a column

words = 'one two three'.split()

df.assign(counts=df.texts.str.count('|'.join(words)))

        texts  counts
0  throne one       2
1     bar one       1
2     foo two       1
3   bar three       1
4     foo two       1
5     bar two       1
6     foo one       1
7   foo three       1
8   one three       2
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #py #count #word #present #column
ADD COMMENT
Topic
Name
8+4 =