Math#
Function |
Description |
---|---|
Returns the absolute value of the input column. |
|
Returns the cube root (β) of a number. |
|
Returns the nearest integer closest from zero. |
|
Returns the integer quotient of the division. |
|
Computes the exponential of the given value. |
|
Returns the nearest integer away from zero. |
|
Computes the natural logarithm of the given value. |
|
Computes the |
|
Computes the logarithm of the given value in base 2. |
|
Computes the logarithm of the given value in base 10. |
|
Computes the natural logarithm of βgiven value plus oneβ. |
|
Returns the remainder of a numeric expression divided by another numeric expression. |
|
Returns a (very good) approximation of π. |
|
Returns the value to the power of the given exponent. |
|
Round a number to |
|
Returns the sign of the argument as -1, 0, or +1. |
|
Returns the square root (β) of a number. |
ABS#
Returns the absolute value of the input column.
Example:
df = pl.DataFrame({"a": [-1.0, 0.0, 1.0, -2.0]})
df.sql("""
SELECT a, ABS(a) AS abs_a FROM self
""")
# shape: (4, 2)
# ββββββββ¬ββββββββ
# β a β abs_a β
# β --- β --- β
# β f64 β f64 β
# ββββββββͺββββββββ‘
# β -1.0 β 1.0 β
# β 0.0 β 0.0 β
# β 1.0 β 1.0 β
# β -2.0 β 2.0 β
# ββββββββ΄ββββββββ
CBRT#
Returns the cube root (β) of a number.
Example:
df = pl.DataFrame({"a": [1.0, 2.0, 4.0]})
df.sql("""
SELECT a, CBRT(a) AS cbrt_a FROM self
""")
# shape: (3, 2)
# βββββββ¬βββββββββββ
# β a β cbrt_a β
# β --- β --- β
# β f64 β f64 β
# βββββββͺβββββββββββ‘
# β 1.0 β 1.0 β
# β 2.0 β 1.259921 β
# β 4.0 β 1.587401 β
# βββββββ΄βββββββββββ
CEIL#
Returns the nearest integer closest from zero.
Aliases
CEILING
Example:
df = pl.DataFrame({"a": [0.1, 2.8, 4.30]})
df.sql("""
SELECT a, CEIL(a) AS ceil_a FROM self
""")
# shape: (3, 2)
# βββββββ¬βββββββββ
# β a β ceil_a β
# β --- β --- β
# β f64 β f64 β
# βββββββͺβββββββββ‘
# β 0.1 β 1.0 β
# β 2.8 β 3.0 β
# β 4.3 β 5.0 β
# βββββββ΄βββββββββ
DIV#
Returns the integer quotient of the division.
Example:
df = pl.DataFrame({"a": [-10.0, 6.5, 25.0]})
df.sql("""
SELECT a, DIV(a, 2) AS a_div_2, DIV(a, 5) AS a_div_5 FROM self
""")
# shape: (3, 3)
# βββββββββ¬ββββββββββ¬ββββββββββ
# β a β a_div_2 β a_div_5 β
# β --- β --- β --- β
# β f64 β i64 β i64 β
# βββββββββͺββββββββββͺββββββββββ‘
# β -10.0 β -5 β -2 β
# β 6.5 β 3 β 1 β
# β 25.0 β 12 β 5 β
# βββββββββ΄ββββββββββ΄ββββββββββ
EXP#
Computes the exponential of the given value.
Example:
df = pl.DataFrame({"a": [1, 2, 4]})
df.sql("""
SELECT a, EXP(a) AS exp_a FROM self
""")
# shape: (3, 2)
# βββββββ¬βββββββββββ
# β a β exp_a β
# β --- β --- β
# β i64 β f64 β
# βββββββͺβββββββββββ‘
# β 1 β 2.718282 β
# β 2 β 7.389056 β
# β 4 β 54.59815 β
# βββββββ΄βββββββββββ
FLOOR#
Returns the nearest integer away from zero.
Example:
df = pl.DataFrame({"a": [0.1, 2.8, 4.30]})
df.sql("""
SELECT a, FLOOR(a) AS floor_a FROM self
""")
# shape: (3, 2)
# βββββββ¬ββββββββββ
# β a β floor_a β
# β --- β --- β
# β f64 β f64 β
# βββββββͺββββββββββ‘
# β 0.1 β 0.0 β
# β 2.8 β 2.0 β
# β 4.3 β 4.0 β
# βββββββ΄ββββββββββ
LN#
Computes the natural logarithm of the given value.
Example:
df = pl.DataFrame({"a": [1, 2, 4]})
df.sql("""
SELECT a, LN(a) AS ln_a FROM self
""")
# shape: (3, 2)
# βββββββ¬βββββββββββ
# β a β ln_a β
# β --- β --- β
# β i64 β f64 β
# βββββββͺβββββββββββ‘
# β 1 β 0.0 β
# β 2 β 0.693147 β
# β 4 β 1.386294 β
# βββββββ΄βββββββββββ
LOG#
Computes the base
logarithm of the given value.
Example:
df = pl.DataFrame({"a": [1, 2, 4]})
df.sql("""
SELECT a, LOG(a, 16) AS log16_a FROM self
""")
# shape: (3, 2)
# βββββββ¬ββββββββββ
# β a β log16_a β
# β --- β --- β
# β i64 β f64 β
# βββββββͺββββββββββ‘
# β 1 β 0.0 β
# β 2 β 0.25 β
# β 4 β 0.5 β
# βββββββ΄ββββββββββ
LOG2#
Computes the logarithm of the given value in base 2.
Example:
df = pl.DataFrame({"a": [1, 2, 4]})
df.sql("""
SELECT a, LOG2(a) AS a_log2 FROM self
""")
# shape: (3, 2)
# βββββββ¬βββββββββ
# β a β a_log2 β
# β --- β --- β
# β i64 β f64 β
# βββββββͺβββββββββ‘
# β 1 β 0.0 β
# β 2 β 1.0 β
# β 4 β 2.0 β
# βββββββ΄βββββββββ
LOG10#
Computes the logarithm of the given value in base 10.
Example:
df = pl.DataFrame({"a": [1, 2, 4]})
df.sql("""
SELECT a, LOG10(a) AS log10_a FROM self
""")
# shape: (3, 2)
# βββββββ¬ββββββββββ
# β a β log10_a β
# β --- β --- β
# β i64 β f64 β
# βββββββͺββββββββββ‘
# β 1 β 0.0 β
# β 2 β 0.30103 β
# β 4 β 0.60206 β
# βββββββ΄ββββββββββ
LOG1P#
Computes the natural logarithm of βgiven value plus oneβ.
Example:
df = pl.DataFrame({"a": [1, 2, 4]})
df.sql("""
SELECT a, LOG1P(a) AS log1p_a FROM self
""")
# shape: (3, 2)
# βββββββ¬βββββββββββ
# β a β log1p_a β
# β --- β --- β
# β i64 β f64 β
# βββββββͺβββββββββββ‘
# β 1 β 0.693147 β
# β 2 β 1.098612 β
# β 4 β 1.609438 β
# βββββββ΄βββββββββββ
MOD#
Returns the remainder of a numeric expression divided by another numeric expression.
Example:
df = pl.DataFrame({"x": [0, 1, 2, 3, 4]})
df.sql("""
SELECT x, MOD(x, 2) AS a_mod_2 FROM self
""")
# shape: (5, 2)
# βββββββ¬ββββββββββ
# β x β a_mod_2 β
# β --- β --- β
# β i64 β i64 β
# βββββββͺββββββββββ‘
# β 0 β 0 β
# β 1 β 1 β
# β 2 β 0 β
# β 3 β 1 β
# β 4 β 0 β
# βββββββ΄ββββββββββ
PI#
Returns a (good) approximation of π.
Example:
df.sql("""
SELECT PI() AS pi FROM self
""")
# shape: (1, 1)
# ββββββββββββ
# β pi β
# β --- β
# β f64 β
# ββββββββββββ‘
# β 3.141593 β
# ββββββββββββ
POW#
Returns the value to the power of the given exponent.
Aliases
POWER
Example:
df = pl.DataFrame({"x": [0, 1, 2, 4]})
df.sql("""
SELECT x, POW(x, 8) AS x_pow_8 FROM self
""")
# shape: (4, 2)
# βββββββ¬ββββββββββ
# β x β x_pow_8 β
# β --- β --- β
# β i64 β i64 β
# βββββββͺββββββββββ‘
# β 0 β 0 β
# β 1 β 1 β
# β 2 β 256 β
# β 4 β 65536 β
# βββββββ΄ββββββββββ
ROUND#
Round a number to x
decimals (default: 0) away from zero.
Example:
df = pl.DataFrame({"x": [-0.45, -1.81, 2.25, 3.99]})
df.sql("""
SELECT x, ROUND(x) AS x_round, ROUND(x, 1) AS x_round_1 FROM self
""")
# shape: (4, 3)
# βββββββββ¬ββββββββββ¬ββββββββββββ
# β x β x_round β x_round_1 β
# β --- β --- β --- β
# β f64 β f64 β f64 β
# βββββββββͺββββββββββͺββββββββββββ‘
# β -0.45 β -0.0 β -0.5 β
# β -1.81 β -2.0 β -1.8 β
# β 2.25 β 2.0 β 2.3 β
# β 3.99 β 4.0 β 4.0 β
# βββββββββ΄ββββββββββ΄ββββββββββββ
SIGN#
Returns the sign of the argument as -1, 0, or +1.
Example:
df = pl.DataFrame({"x": [0.4, -1, 0, -2, 4]})
df.sql("""
SELECT x, SIGN(x) AS sign_x FROM self
""")
# shape: (5, 2)
# ββββββββ¬βββββββββ
# β x β sign_x β
# β --- β --- β
# β f64 β i64 β
# ββββββββͺβββββββββ‘
# β 0.4 β 1 β
# β -1.0 β -1 β
# β 0.0 β 0 β
# β -2.0 β -1 β
# β 4.0 β 1 β
# ββββββββ΄βββββββββ
SQRT#
Returns the square root (β) of a number.
Example:
df = pl.DataFrame({"x": [2, 16, 4096, 65536]})
df.sql("""
SELECT x, SQRT(x) AS sqrt_x FROM self
""")
# shape: (4, 2)
# βββββββββ¬βββββββββββ
# β x β sqrt_x β
# β --- β --- β
# β i64 β f64 β
# βββββββββͺβββββββββββ‘
# β 2 β 1.414214 β
# β 16 β 4.0 β
# β 4096 β 64.0 β
# β 65536 β 256.0 β
# βββββββββ΄βββββββββββ