polars.Expr.str.starts_with#
- Expr.str.starts_with(prefix: str | Expr) Expr [source]#
Check if string values start with a substring.
- Parameters:
- prefix
Prefix substring.
See also
Examples
>>> df = pl.DataFrame({"fruits": ["apple", "mango", None]}) >>> df.with_columns( ... pl.col("fruits").str.starts_with("app").alias("has_prefix"), ... ) shape: (3, 2) ┌────────┬────────────┐ │ fruits ┆ has_prefix │ │ --- ┆ --- │ │ str ┆ bool │ ╞════════╪════════════╡ │ apple ┆ true │ │ mango ┆ false │ │ null ┆ null │ └────────┴────────────┘
Using
starts_with
as a filter condition:>>> df.filter(pl.col("fruits").str.starts_with("app")) shape: (1, 1) ┌────────┐ │ fruits │ │ --- │ │ str │ ╞════════╡ │ apple │ └────────┘