otp.Operation.str.repeat#

repeat(repeats)#

Duplicate a string repeats times.

Parameters

repeats (int or Column or Operation) – Number of copies of existed strings in new ones.

Returns

String repeated repeats times.

Return type

Operation

Note

  • Alternative for the repeat function is multiplication.

  • The returned string has the same maximum length as the original field.

Examples

>>> data = otp.Ticks(X=["Banana", "Ananas", "Apple"])
>>> data["X"] = data["X"].str.repeat(3)
>>> otp.run(data)["X"]
0    BananaBananaBanana
1    AnanasAnanasAnanas
2       AppleAppleApple
Name: X, dtype: object
>>> data = otp.Ticks(X=["Banana", "Ananas", "Apple"], TIMES=[1, 3, 2])
>>> data["X"] = data["X"].str.repeat(data["TIMES"])
>>> otp.run(data)["X"]
0                Banana
1    AnanasAnanasAnanas
2            AppleApple
Name: X, dtype: object

The returned string has the same maximum length as the original field.

>>> data = otp.Ticks(X=[otp.string[9]("Banana")])
>>> data["Y"] = data["X"].str.repeat(3)
>>> otp.run(data)["Y"]
0    BananaBan
Name: Y, dtype: object

repeat does the same thing as multiplication by a non-negative int

>>> data = otp.Ticks(X=["Banana"], N=[2])
>>> data["X2"] = data["X"] * data["N"]
>>> data["X3"] = data["X"] * 3
>>> otp.run(data)[["X", "X2", "X3"]]
        X            X2                  X3
0  Banana  BananaBanana  BananaBananaBanana