Loading...

vastorbit.VastColumn.str_count

VastColumn.str_count(pat: str) VastFrame

Computes the number of matches for the regular expression in each record of the VastColumn. The VastColumn will be transformed.

Parameters:

pat (str) – regular expression.

Returns:

self._parent

Return type:

VastFrame

Examples

Let’s begin by importing vastorbit.

import vastorbit as vo

Let’s generate a small dataset using the following data:

data = vo.VastFrame(
    {
        "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” VastColumn.

data["subjects"].str_count(pat = "English").select(
    [
        "rollno",
        "subjects as english_count",
    ]
)
Abc
rollno
Varchar(1)
123
english_count
Bigint
121
230
340
411
Rows: 1-4 | Columns: 2

See also

VastFrame.str_contains() : Validates the regular expression.
VastFrame.str_extract() : Extracts the Regular Expression.
VastFrame.str_replace() : Replaces the Regular Expression.
VastFrame.str_slice() : Slices the Regular Expression.