verticapy.vDataColumn.str_count#
- vDataColumn.str_count(pat: str) vDataFrame #
Computes the number of matches for the regular expression in each record of the vDataColumn. The vDataColumn will be transformed.
Parameters#
- pat: str
regular expression.
Returns#
- vDataFrame
self._parent
Examples#
Let’s begin by importing VerticaPy.
import verticapy as vp
Let’s generate a small dataset using the following data:
data = vp.vDataFrame( { "rollno": ['1', '2', '3', '4'], "subjects": [ 'English, Math', 'English, Math, Computer', 'Math, Computer, Science', 'Math, Science', ], } )
Let’s count number of times “English” appears in “subjects” vDataColumn.
data["subjects"].str_count(pat = "English").select( [ "rollno", "subjects as english_count", ] )
AbcrollnoVarchar(1)100%123english_countInteger100%1 1 1 2 2 1 3 3 0 4 4 0 See also
vDataFrame.
str_contains()
: Validates the regular expression.vDataFrame.
str_extract()
: Extracts the Regular Expression.vDataFrame.
str_replace()
: Replaces the Regular Expression.vDataFrame.
str_slice()
: Slices the Regular Expression.