This is a follow up on this stack overflow question
Select by partial string from a pandas DataFrame
Which returns rows based on a partial string.
df[df['A'].str.contains("hello")]
My question is, how to return rows which contain multiple instances of a partial string.
For example, what if I want to return all rows where a particular column contains 3 instances of the partial string 'ology'. How would I do that?
Example:
testdf = pd.DataFrame([['test1', 'this is biology mixed with zoology', ], ['test2', 'the cat and bat teamed up to find some food'], ['test2' , 'anthropology with pharmacology and biology']])
testdf.head()
>0 1
>0 test1 this is biology mixed with zoology
>1 test2 the cat and bat teamed up to find some food
>2 test2 anthropology with pharmacology and biology
testdf = testdf[testdf[1].str.contains("ology")]
testdf.head()
>0 1
>0 test1 this is biology mixed with zoology
>2 test2 anthropology with pharmacology and biology
What i am looking for is rows with 3 instances of 'ology' , so it would only return the last row
>2 test2 anthropology with pharmacology and biology