otp.Operation.str.contains#

contains(substr)#

Check if the string contains substr.

Parameters

substr (str or Column or Operation) – A substring to search for within the string.

Returns

Column containing value 1.0 if the string contains the substring, 0.0 otherwise

Return type

Operation

Examples

>>> data = otp.Ticks(X=["hello", "world!"])
>>> data["CONTAINS"] = data["X"].str.contains("hel")
>>> otp.run(data)["CONTAINS"]
0    1.0
1    0.0
Name: CONTAINS, dtype: float64
>>> data = otp.Ticks(X=['hello', 'big', 'world!'],
...                  Y=['hel', 'wor', 'wor'])
>>> data["CONTAINS"] = data["X"].str.contains(data["Y"])
>>> otp.run(data)["CONTAINS"]
0    1.0
1    0.0
2    1.0
Name: CONTAINS, dtype: float64

Can be used for filtering.

>>> data = otp.Ticks(X=["Hello", "World"])
>>> with_substr,  wo_substr = data[data["X"].str.contains("Hel")]
>>> otp.run(with_substr)["X"]
0    Hello
Name: X, dtype: object