Answers for "py - count if a word is present in a column"

0

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
Posted by: Guest on March-19-2021

Code answers related to "py - count if a word is present in a column"

Python Answers by Framework

Browse Popular Code Answers by Language