Loading...

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",
    ]
)
Abc
rollno
Varchar(1)
100%
123
english_count
Integer
100%
111
221
330
440

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.