otp.Operation.str.substr#
- substr(start, n_bytes=None, rtrim=False)#
Return
n_bytes
characters starting fromstart
.For a positive
start
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. If then_bytes
parameter is omitted, returns the part of the input string starting atstart
till the end of the string.- 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, 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