Skip to main content
Version: 1.9.0

Expr.str.replace

def replace(
pattern: str | Expr,
value: str | Expr,
literal: bool = False,
n: int = 1,
) -> Expr

Categories: string

Replace the first occurence of a pattern with the given string.

Parameters

parameter
pattern

The pattern to replace.

parameter
value

The value to replace the pattern with.

parameter
literal

Take the pattern as a literal string (not a regex).

parameter
n

Number of matches to replace.

Examples

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("a"), td.col("a").str.replace("b", "X").alias("replace"))
>>>
┌───────────┬───────────┐
│ a ┆ replace │
------
strstr
╞═══════════╪═══════════╡
│ a bAb c d ┆ a XAb c d │
│ bCbb c d ┆ XCbb c d │
│ bb ┆ Xb │
│ b ┆ X │
│ a ┆ a │
│ null ┆ null │
└───────────┴───────────┘