polars.internals.expr.string.ExprStringNameSpace.strip#

ExprStringNameSpace.strip(matches: Optional[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  │
└───────┘