polars.Expr.str.ends_with#

Expr.str.ends_with(sub: str) Expr[source]#

Check if string values end with a substring.

Parameters:
sub

Suffix substring.

See also

contains

Check if string contains a substring that matches a regex.

starts_with

Check if string values start with a substring.

Examples

>>> df = pl.DataFrame({"fruits": ["apple", "mango", None]})
>>> df.with_column(
...     pl.col("fruits").str.ends_with("go").alias("has_suffix"),
... )
shape: (3, 2)
┌────────┬────────────┐
│ fruits ┆ has_suffix │
│ ---    ┆ ---        │
│ str    ┆ bool       │
╞════════╪════════════╡
│ apple  ┆ false      │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
│ mango  ┆ true       │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
│ null   ┆ null       │
└────────┴────────────┘

Using ends_with as a filter condition:

>>> df.filter(pl.col("fruits").str.ends_with("go"))
shape: (1, 1)
┌────────┐
│ fruits │
│ ---    │
│ str    │
╞════════╡
│ mango  │
└────────┘