str.replace_all

ColExpr.str.replace_all(
substr: str,
replacement: str,
) ColExpr[String][source]

Replaces all occurrences of a given substring by a different string.

Parameters:
  • substr – The string to replace.

  • replacement – The replacement string.

Examples

>>> t = pdt.Table(
...     {
...         "a": ["  BCD ", "-- 00", " A^^u", "-O2", ""],
...         "b": ["12431", "transform", "12__*m", "   ", "abbabbabba"],
...     },
...     name="string table",
... )
>>> (
...     t
...     >> mutate(
...         r=t.a.str.replace_all("-", "?"),
...         s=t.b.str.replace_all("ansf", "[---]"),
...         u=t.b.str.replace_all("abba", "#"),
...     )
...     >> show()
... )
Table string table, backend: PolarsImpl
shape: (5, 5)
┌────────┬────────────┬────────┬────────────┬───────────┐
│ a      ┆ b          ┆ r      ┆ s          ┆ u         │
│ ---    ┆ ---        ┆ ---    ┆ ---        ┆ ---       │
│ str    ┆ str        ┆ str    ┆ str        ┆ str       │
╞════════╪════════════╪════════╪════════════╪═══════════╡
│   BCD  ┆ 12431      ┆   BCD  ┆ 12431      ┆ 12431     │
│ -- 00  ┆ transform  ┆ ?? 00  ┆ tr[---]orm ┆ transform │
│  A^^u  ┆ 12__*m     ┆  A^^u  ┆ 12__*m     ┆ 12__*m    │
│ -O2    ┆            ┆ ?O2    ┆            ┆           │
│        ┆ abbabbabba ┆        ┆ abbabbabba ┆ #bb#      │
└────────┴────────────┴────────┴────────────┴───────────┘