Given this dataframe:
df = pl.DataFrame({"s": ["pear", None, "papaya", "dragonfruit"]})
I want to remove the last X chars, e.g. remove the last 2 chars from the column. This obviously doesn't do what I want:
df.with_columns(
pl.col("s").str.slice(2).alias("s_sliced"),
)
I'd like the result to be:
shape: (4, 2)
┌─────────────┬──────────┐
│ s ┆ s_sliced │
│ --- ┆ --- │
│ str ┆ str │
╞═════════════╪══════════╡
│ pear ┆ pe │
│ null ┆ null │
│ papaya ┆ papa │
│ dragonfruit ┆ dragonfru|