Excerpt |
---|
Counts the number of instances of a specified pattern in a column and writes that value into a newly generated column. Source column is unchanged. |
D code |
---|
countpattern col: myCol on: 'honda' |
Output: Generates a new column containing the number of instances of the string honda
that appear in each row of the column, myCol
.
D code |
---|
countpattern col:column_ref [ignoreCase:true|false] [after:start_point | from: start_point] [before:end_point | to:end_point] [on:'exact_match'] |
Token | Required? | Data Type | Description |
---|
countpattern | Y | transform | Name of the transform |
col | Y | string | Source column name |
ignoreCase | N | boolean | If true , matching is case-insensitive. |
Matching parameters:
Info |
---|
NOTE: At least one of the following parameters must be included to specify the pattern to count: after , before , from , on , to . |
Token | Required? | Data Type | Description |
---|
after | N | string | String literal or pattern that precedes the pattern to match |
before | N | string | String literal or pattern that appears after the pattern to match |
from | N | string | String literal or pattern that identifies the start of the pattern to match |
on | N | string | String literal or pattern that identifies the pattern to match. |
to | N | string | String literal or pattern that identifies the end of the pattern to match |
Identifies the column to which to apply the transform. You can specify only one column.
D code |
---|
countpattern col: MyCol on: 'MyString' |
Output: Counts the number of instances of the value MyString
in the MyCol
column and writes this value to a new column.
Required? | Data Type |
---|
Yes | String (column name) |
D code |
---|
countpattern col: MyCol after: 'entry:' |
Output: Counts 1
if there is anything that appears in the MyCol
column value after the string entry:
. If the value entry:
does not appear in the column, the output value is 0
.
Include Page |
---|
| after Parameter |
---|
| after Parameter |
---|
|
Required? | Data Type |
---|
No | String (string literal or pattern) |
- The
after
and from
parameters are very similar. from
includes the matching value as part of the extracted string. after
can be used with either to
, on
, or before
. See Pattern Clause Position Matching
Include Page |
---|
| before Parameter |
---|
| before Parameter |
---|
|
D code |
---|
countpattern col: MyCol before: '|' |
Output:
- Counts
1
if there is a value that appears before the pipe character (|
) in the MyCol
column, and no other pattern parameter is specified. If the before
value does not appear in the column, the output value is 0
. - If another pattern parameter such as
after
is specified, the total count of instances is written to the new column.
Required? | Data Type |
---|
No | String or pattern |
- The
before
and to
parameters are very similar. to
includes the matching value as part of the extracted string. before
can be used with either from,
on
, or after
. See Pattern Clause Position Matching .
Include Page |
---|
| from Parameter |
---|
| from Parameter |
---|
|
D code |
---|
countpattern col: MyCol from: 'go:' |
Output:
- Counts
1
if contents from MyCol
that occur from go:
, to the end of the cell when no other pattern parameter is specified. If go:
does not appear in the column, the output value is blank. - If another pattern parameter such as
to
is specified, the total count of instances is written to the new column.
Required? | Data Type |
---|
No | String or pattern |
- The
after
and from
parameters are very similar. from
includes the matching value as part of the extracted string. from
can be used with either to
or before
. See Pattern Clause Position Matching .
D code |
---|
countpattern col: MyCol on: `###ERROR` |
Tip |
---|
Tip: You can insert the Unicode equivalent character for this parameter value using a regular expression of the form /\uHHHH/ . For example, /\u0013/ represents Unicode character 0013 (carriage return). For more information, see Supported Special Regular Expression Characters. |
Required? | Data Type |
---|
No | String (literal, regular expression, or |
D code |
---|
countpattern col:MyCol from:'note:' to: `/` |
Output:
- Counts instances from
MyCol
column of all values that begin with note:
up to a backslash character. - If a second pattern parameter is not specified, then this value is either
0
or 1
.
Required? | Data Type |
---|
No | String or pattern |
- The
before
and to
parameters are very similar. to
includes the matching value as part of the extracted string. to
can be used with either from
or after
. See Pattern Clause Position Matching.
Include Page |
---|
| ignoreCase Parameter |
---|
| ignoreCase Parameter |
---|
|
D code |
---|
countpattern col: MyCol on: 'My String' ignoreCase: true |
Output: Counts the instances of the following values if they appear in the MyCol
column: My String
, my string
, My string
, etc.
Required? | Data Type |
---|
No | Boolean |
Include Page |
---|
| EXAMPLE - Countpattern Transform |
---|
| EXAMPLE - Countpattern Transform |
---|
|
D s also |
---|
label | wrangle_transform_countpattern |
---|
|