polars.Expr.str.strip_prefix#

Expr.str.strip_prefix(prefix: IntoExpr) Expr[source]#

Remove prefix.

The prefix will be removed from the string exactly once, if found.

Note

This method strips the exact character sequence provided in prefix from the start of the input. To strip a set of characters in any order, use strip_chars_start() instead.

Parameters:
prefix

The prefix to be removed.

Examples

>>> df = pl.DataFrame({"a": ["foobar", "foofoobar", "foo", "bar"]})
>>> df.with_columns(pl.col("a").str.strip_prefix("foo").alias("stripped"))
shape: (4, 2)
┌───────────┬──────────┐
│ a         ┆ stripped │
│ ---       ┆ ---      │
│ str       ┆ str      │
╞═══════════╪══════════╡
│ foobar    ┆ bar      │
│ foofoobar ┆ foobar   │
│ foo       ┆          │
│ bar       ┆ bar      │
└───────────┴──────────┘