Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Python :: python selenium login button class click 
Python :: random word generator django 
Python :: pass in 2 numbers, A and B. You should create a list with A rows and B columns, then populate each cell 
Python :: What are zinc bandages used for? 
Python :: Return the key-value pairs in this RDD to the master as a dictionary. 
Python :: Compute the mean of this RDD’s elements. 
Python :: update profile rasterio pyton 
Python :: Filters rows using the given condition 
Python :: entry point to programming Spark with the Dataset and DataFrame API 
Python :: staff user is not restricting permission in django 
Python :: python seaborn violin stack overflow 
Python :: python setup install_requires local whl 
Python :: install iris 
Python :: introduction python graphviz simple graph examples 
Python :: hashing in python using quadratic probing 
Python :: if using and in python 
Python :: change the size of a button tkinter 
Python :: how to use idl in python 
Python :: Single line Commenting in Python 
Python :: pysheet 
Python :: 52277-36880 
Python :: generic rectangle 
Python :: how to prevent extbackslash in LaTeX from Python 
Python :: download image from url python 
Python :: Django url with primary key 
Python :: run python script with admin rights 
Python :: python chunks 
Python :: The Bytearray Type 
Python :: how to go sown a line in pyton 
Python :: the coding train 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =