otp.Column math operations#

Operation.__abs__()[source]#

Return the absolute value of float or int column.

Examples

>>> t = otp.Tick(A=-1, B=-2.3)
>>> t['A'] = abs(t['A'])
>>> t['B'] = abs(t['B'])
>>> t()[['A', 'B']]
   A    B
0  1  2.3
Operation.__round__(precision=None)[source]#

Rounds value with specified precision.

Parameters

precision (int) – Number from -12 to 12. Positive precision is precision after the floating point. Negative precision is precision before the floating point.

Return type

Operation

Examples

>>> t = otp.Tick(A=1234.5678)
>>> t['B'] = round(t['A'])
>>> t['C'] = round(t['A'], 2)
>>> t['D'] = round(t['A'], -2)
>>> t.to_df()
        Time          A     B        C       D
0 2003-12-01  1234.5678  1235  1234.57  1200.0
Operation.__neg__()[source]#

Return the negative value of float or int column.

Examples

>>> t = otp.Tick(A=1, B=2.3)
>>> t['A'] = -t['A']
>>> t['B'] = -t['B']
>>> t()[['A', 'B']]
   A    B
0 -1 -2.3
Operation.__add__(other)[source]#

Return the sum of column and other value.

Parameters

other (int, float, str, datetime offsets, Column) –

Examples

>>> t = otp.Tick(A=1, B=2.3, C='c', D=otp.datetime(2022, 5, 12))
>>> t['A'] = t['A'] + t['B']
>>> t['B'] = t['B'] + 1
>>> t['C'] = t['C'] + '_suffix'
>>> t['D'] = t['D'] + otp.Day(1)
>>> t()[['A', 'B', 'C', 'D']]
     A    B         C          D
0  3.3  3.3  c_suffix 2022-05-13
Operation.__radd__(other)[source]#

Examples

>>> t = otp.Tick(A=1, B=2.3, C='c', D=otp.datetime(2022, 5, 12))
>>> t['A'] += t['B']
>>> t['B'] += 1
>>> t['C'] += '_suffix'
>>> t['D'] += otp.Day(1)
>>> t()[['A', 'B', 'C', 'D']]
     A    B         C          D
0  3.3  3.3  c_suffix 2022-05-13

See also

__add__

Operation.__sub__(other)[source]#

Subtract other value from column.

Parameters

other (int, float, datetime offsets, Column) –

Examples

>>> t = otp.Tick(A=1, B=2.3, D=otp.datetime(2022, 5, 12))
>>> t['A'] = t['A'] - t['B']
>>> t['B'] = t['B'] - 1
>>> t['D'] = t['D'] - otp.Day(1)
>>> t()[['A', 'B', 'D']]
     A    B          D
0 -1.3  1.3 2022-05-11
Operation.__rsub__(other)[source]#

Examples

>>> t = otp.Tick(A=1, B=2.3, D=otp.datetime(2022, 5, 12))
>>> t['A'] -= t['B']
>>> t['B'] -= 1
>>> t['D'] -= otp.Day(1)
>>> t()[['A', 'B', 'D']]
     A    B          D
0 -1.3  1.3 2022-05-11

See also

__sub__

Operation.__mul__(other)[source]#

Multiply column by other value.

Parameters

other (int, float, str, Column) –

Examples

>>> t = otp.Tick(A=1, B=2.3, C='c')
>>> t['A'] = t['A'] * t['B']
>>> t['B'] = t['B'] * 2
>>> t['C'] = t['C'] * 3
>>> t()[['A', 'B', 'C']]
     A    B    C
0  2.3  4.6  ccc
Operation.__rmul__(other)[source]#

Examples

>>> t = otp.Tick(A=1, B=2.3, C='c')
>>> t['A'] *= t['B']
>>> t['B'] *= 2
>>> t['C'] *= 3
>>> t()[['A', 'B', 'C']]
     A    B    C
0  2.3  4.6  ccc

See also

__mul__

Operation.__truediv__(other)[source]#

Divide column by other value.

Parameters

other (int, float, Column) –

Examples

>>> t = otp.Tick(A=1, B=2.3)
>>> t['A'] = t['A'] / t['B']
>>> t['B'] = t['B'] / 2
>>> t()[['A', 'B']]
          A     B
0  0.434783  1.15
Operation.__rtruediv__(other)[source]#

Examples

>>> t = otp.Tick(A=1, B=2.3)
>>> t['A'] /= t['B']
>>> t['B'] /= 2
>>> t()[['A', 'B']]
          A     B
0  0.434783  1.15

See also

__truediv__

Operation.__mod__(other)[source]#

Return modulo of division of int column by other value.

Parameters

other (int, Column) –

Examples

>>> t = otp.Tick(A=3, B=3)
>>> t['A'] = t['A'] % t['B']
>>> t['B'] = t['B'] % 2
>>> t()[['A', 'B']]
   A  B
0  0  1
Operation.__invert__()[source]#

Return inversion of filter operation.

Examples

>>> t = otp.Ticks(A=range(4))
>>> t, _ = t[~(t['A'] > 1)]
>>> t()[['A']]
   A
0  0
1  1
Operation.__eq__(other)[source]#

Return equality in filter operation.

Examples

>>> t = otp.Ticks(A=range(4))
>>> t, _ = t[(t['A'] == 1)]
>>> t()[['A']]
   A
0  1
Operation.__ne__(other)[source]#

Return inequality in filter operation.

Examples

>>> t = otp.Ticks(A=range(4))
>>> t, _ = t[(t['A'] != 1)]
>>> t()[['A']]
   A
0  0
1  2
2  3
Operation.__or__(other)[source]#

Return logical or in filter operation.

Examples

>>> t = otp.Ticks(A=range(4))
>>> t, _ = t[(t['A'] == 1) | (t['A'] == 2)]
>>> t()[['A']]
   A
0  1
1  2
Operation.__and__(other)[source]#

Return logical and in filter operation.

Examples

>>> t = otp.Ticks(A=[1, 1], B=[1, 2])
>>> t, _ = t[(t['A'] == 1) & (t['B'] == 1)]
>>> t()[['A', 'B']]
   A  B
0  1  1
Operation.__le__(other)[source]#

Return <= in filter operation.

Examples

>>> t = otp.Ticks(A=range(4))
>>> t, _ = t[t['A'] <= 2]
>>> t()[['A']]
   A
0  0
1  1
2  2
Operation.__lt__(other)[source]#

Return < in filter operation.

Examples

>>> t = otp.Ticks(A=range(4))
>>> t, _ = t[t['A'] < 2]
>>> t()[['A']]
   A
0  0
1  1
Operation.__ge__(other)[source]#

Return >= in filter operation.

Examples

>>> t = otp.Ticks(A=range(4))
>>> t, _ = t[t['A'] >= 2]
>>> t()[['A']]
   A
0  2
1  3
Operation.__gt__(other)[source]#

Return > in filter operation.

Examples

>>> t = otp.Ticks(A=range(4))
>>> t, _ = t[t['A'] > 2]
>>> t()[['A']]
   A
0  3