str.slice¶
- ColExpr.str.slice( ) ColExpr[String][source]¶
Returns a substring of the input string.
- Parameters:
offset – The 0-based index of the first character included in the result.
n – The number of characters to include. If the string is shorter than offset + n, the result only includes as many characters as there are.
Examples
>>> t = pdt.Table( ... { ... "a": [" BCD ", "-- 00", " A^^u", "-O2", ""], ... "b": ["12431", "transform", "12__*m", " ", "abbabbabba"], ... }, ... name="string table", ... ) >>> ( ... t ... >> mutate( ... j=t.a.str.slice(0, 2), ... k=t.b.str.slice(4, 10), ... ) ... >> show() ... ) Table string table, backend: PolarsImpl shape: (5, 4) ┌────────┬────────────┬─────┬────────┐ │ a ┆ b ┆ j ┆ k │ │ --- ┆ --- ┆ --- ┆ --- │ │ str ┆ str ┆ str ┆ str │ ╞════════╪════════════╪═════╪════════╡ │ BCD ┆ 12431 ┆ ┆ 1 │ │ -- 00 ┆ transform ┆ -- ┆ sform │ │ A^^u ┆ 12__*m ┆ A ┆ *m │ │ -O2 ┆ ┆ -O ┆ │ │ ┆ abbabbabba ┆ ┆ bbabba │ └────────┴────────────┴─────┴────────┘