otp.Operation.str.substr#
- substr(start, n_bytes=None, rtrim=False)#
Return
n_bytes
characters starting fromstart
. For a positivestart
returnnum_bytes
of the string, starting from the position specified bystart
(0-based). For a negativestart
, the position is counted from the end of the string (when specifying a negative index, please take into account that a field may have whitespace at the end, which you could remove bytrim()
). If then_bytes
parameter is omitted, returns the part of the input string starting at start.- Parameters
- Returns
Substring of string (
n_bytes
length starting withstart
).- Return type
Examples
>>> data = otp.Ticks(X=["abcdef", "12345"], START_INDEX=[2, 1], N=[2, 3]) >>> data["FIRST_3"] = data["X"].str.substr(0, 3) >>> data["LAST_3"] = data["X"].str.substr(-3, 3, rtrim=True) >>> data["CENTER"] = data["X"].str.substr(data["START_INDEX"], data["N"]) >>> otp.run(data)[["FIRST_3", "LAST_3", "CENTER"]] FIRST_3 LAST_3 CENTER 0 abc def cd 1 123 345 234