py count if a word is present in a column

Solutions on MaxInterview for py count if a word is present in a column by the best coders in the world

showing results for - "py count if a word is present in a column"
Felix
11 Jul 2016
1words = 'one two three'.split()
2
3df.assign(counts=df.texts.str.count('|'.join(words)))
4
5        texts  counts
60  throne one       2
71     bar one       1
82     foo two       1
93   bar three       1
104     foo two       1
115     bar two       1
126     foo one       1
137   foo three       1
148   one three       2
15
similar questions
queries leading to this page
py count if a word is present in a column