Expr.str.count_matches
methodView source ↗
def count_matches(pattern: str | Expr, literal: bool = False) -> Expr
Categories: string
Counts the ocurrrences of the given pattern in the string.
Parameters
parameter
patternThe pattern to extract.
parameter
literalTake the pattern as a literal string (not a regex).
Examples
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("a"), td.col("a")
.str.count_matches("b.").alias("count_matches"))
>>>
┌───────────┬───────────────┐
│ a ┆ count_matches │
│ --- ┆ --- │
│ str ┆ u32 │
╞═══════════╪═══════════════╡
│ a bAb c d ┆ 2 │
│ bCbb c d ┆ 2 │
│ bb ┆ 1 │
│ b ┆ 0 │
│ a ┆ 0 │
│ null ┆ null │
└───────────┴───────────────┘