tabsdata.tableframe.expr.string.ExprStringNameSpace.replace#
- ExprStringNameSpace.replace(pattern: str | Expr, value: str | Expr, *, literal: bool = False, n: int = 1) Expr [source]#
Replace the first occurence of a pattern with the given string.
- Parameters:
pattern – The pattern to replace.
value – The value to replace the pattern with.
literal – Take the pattern as a literal string (not a regex).
n – Number of matches to replace.
Example:
>>> import tabsdata as td >>> >>> tf: td.TableFrame ... >>> >>> tf.select(td.col("a"), td.col("a").str.replace("b", "X").alias("replace")) >>> ┌───────────┬───────────┐ │ a ┆ replace │ │ --- ┆ --- │ │ str ┆ str │ ╞═══════════╪═══════════╡ │ a bAb c d ┆ a XAb c d │ │ bCbb c d ┆ XCbb c d │ │ bb ┆ Xb │ │ b ┆ X │ │ a ┆ a │ │ null ┆ null │ └───────────┴───────────┘