Create subslices of the string values of a Utf8 Series.
s = Polars::Series.new("s", ["pear", nil, "papaya", "dragonfruit"]) s.str.slice(-3) # => # shape: (4,) # Series: 's' [str] # [ # "ear" # null # "aya" # "uit" # ]
Using the optional length parameter
length
s.str.slice(4, 3) # => # shape: (4,) # Series: 's' [str] # [ # "" # null # "ya" # "onf" # ]
Parameters:
Start index. Negative indexing is supported.
Length of the slice. If set to nil (default), the slice is taken to the end of the string.
nil
Returns:
1092 1093 1094 1095
# File 'lib/polars/string_name_space.rb', line 1092 def slice(offset, length = nil) s = Utils.wrap_s(_s) s.to_frame.select(Polars.col(s.name).str.slice(offset, length)).to_series end