polars.Expr.str.strip#

Expr.str.strip(matches: None | str = None) Expr[source]#

Remove leading and trailing whitespace.

Parameters:
matches

An optional single character that should be trimmed

Examples

>>> df = pl.DataFrame({"foo": [" lead", "trail ", " both "]})
>>> df.select(pl.col("foo").str.strip())
shape: (3, 1)
┌───────┐
│ foo   │
│ ---   │
│ str   │
╞═══════╡
│ lead  │
├╌╌╌╌╌╌╌┤
│ trail │
├╌╌╌╌╌╌╌┤
│ both  │
└───────┘