polars.Expr.str.ends_with#

Expr.str.ends_with(suffix: str | Expr) Expr[source]#

Check if string values end with a substring.

Parameters:
suffix

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_columns(
...     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  │
└────────┘