otp.Operation.str.substr#
- _StrAccessor.substr(start, n_bytes=None, rtrim=False, *, utf8=False)#
Return
n_bytescharacters starting fromstart.For a positive
startreturnnum_bytesof the string, starting from the position specified bystart(0-based). For a negativestart, the position is counted from the end of the string. If then_bytesparameter is omitted, returns the part of the input string starting atstarttill the end of the string.- Parameters:
start (int or Column or Operation) – Index of first symbol in substring
n_bytes (int or Column or Operation) – Number of bytes in substring
rtrim (bool) – If set to
True, original string will be trimmed from the right side before getting the substring, this can be useful with negativestartindex.utf8 (bool) – If set, then UTF-8 format is supported.
- Returns:
Substring of string (
n_byteslength 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, rtrim=True) >>> data['CENTER'] = data['X'].str.substr(data['START_INDEX'], data['N']) >>> otp.run(data) Time X START_INDEX N FIRST_3 LAST_3 CENTER 0 2003-12-01 00:00:00.000 abcdef 2 2 abc def cd 1 2003-12-01 00:00:00.001 12345 1 3 123 345 234
See also
SUBSTR OneTick functionSUBSTR_UTF8 OneTick function