otp.Operation.str.token#
- token(sep=' ', n=0)#
Breaks the value into tokens based on the delimiter
sep
and returns token at positionn
(zero-based).If there are not enough tokens to get the one at position
n
, then empty string is returned.- Parameters
- Returns
token at position
n
or empty string.- Return type
Examples
>>> data = otp.Tick(X='NYSE_TAQ::TRD') >>> data['Y'] = data['X'].str.token(':', -1) >>> otp.run(data) Time X Y 0 2003-12-01 NYSE_TAQ::TRD TRD
Other columns can be used as parameters too:
>>> data = otp.Tick(X='NYSE_TAQ::TRD', SEP=':', N=-1) >>> data['Y'] = data['X'].str.token(data['SEP'], data['N']) >>> otp.run(data) Time X SEP N Y 0 2003-12-01 NYSE_TAQ::TRD : -1 TRD
If index is out of range, then empty string is returned:
>>> data = otp.Tick(X='NYSE_TAQ::TRD') >>> data['Y'] = data['X'].str.token(':', 999) >>> otp.run(data) Time X Y 0 2003-12-01 NYSE_TAQ::TRD