tabsdata.tableframe.expr.expr
ErrorCode | |
TableFrameError | Exception raised when handling a (Td)TableFrame. |
TdExpr | |
TdExpr.abs | Return the abso lute value of the expression. |
TdExpr.add | Equivalent to the + operator. |
TdExpr.alias | Set the name for a column or expression. |
TdExpr.and_ | Bitwise and operator with the given expressions. |
TdExpr.arccos | Calculate the inverse cosine of the element value. |
TdExpr.arccosh | Calculate the inverse hyperbolic cosine of the element value. |
TdExpr.arcsin | Calculate the inverse sine of the element value. |
TdExpr.arcsinh | Calculate the inverse hyperbolic sine of the element value. |
TdExpr.arctan | Calculate the inverse tangent of the element value. |
TdExpr.arctanh | Calculate the inverse hyperbolic tangent of the element value. |
TdExpr.cast | Cast a value to d different type. |
TdExpr.cbrt | Calculate the cub root of the element value. |
TdExpr.ceil | Round up the expression to the next integer value. |
TdExpr.clip | For element values outside the lower and upper bounds, lower values are replaced with the lower bound and upper values with the upper bound. |
TdExpr.cos | Calculate the cosine of the element value. |
TdExpr.cosh | Calculate the hyperbolic cosine of the element value. |
TdExpr.cot | Calculate the cotangent of the element value. |
TdExpr.count | Aggregation operation that counts the non null values of the given column in the group. |
TdExpr.degrees | Convert a radian value to degrees |
TdExpr.diff | Compute the difference between an element value and the element value of the specified relative row. |
TdExpr.eq | Compare if 2 expressions are equal, equivalent to expr == other. |
TdExpr.eq_missing | Compare if 2 expressions are equal an, equivalent to expr == other. |
TdExpr.exp | Calculate the exponential of the element value. |
TdExpr.fill_nan | Replace NaN values with the given value. |
TdExpr.fill_null | Replace null values with the given value. |
TdExpr.filter | Apply a filter predicate to an expression. |
TdExpr.first | Get the first element. |
TdExpr.floor | Round down the expression to the previous integer value. |
TdExpr.floordiv | Calculate the floor on the division. |
TdExpr.ge | Greater or equal operator. |
TdExpr.gt | Greater than operator. |
TdExpr.hash | Compute the hash of an element value. |
TdExpr.is_between | If an expression is between the given bounds. |
TdExpr.is_finite | If an element value is finite. |
TdExpr.is_in | If an element value is in the given collection. |
TdExpr.is_infinite | If an element value is infinite. |
TdExpr.is_nan | If an element value is NaN. |
TdExpr.is_not_nan | If an element value is not NaN. |
TdExpr.is_not_null | If an element value is not null (None). |
TdExpr.is_null | If an element value is null (None). |
TdExpr.is_unique | If an element value is unique for all values in the column. |
TdExpr.last | Get the last element. |
TdExpr.le | Less or equal operator. |
TdExpr.len | Aggregation operation that counts the rows in the group. |
TdExpr.log | Calculate the logarithm to the given base. |
TdExpr.log10 | Calculate the logarithm base 10. |
TdExpr.log1p | Calculate the natural logarithm plus one. |
TdExpr.lt | Less than operator. |
TdExpr.max | Aggregation operation that finds the maximum value in the group. |
TdExpr.mean | Aggregation operation that finds the mean of the values in the group. |
TdExpr.median | Aggregation operation that finds the median of the values in the group. |
TdExpr.min | Aggregation operation that finds the minimum value in the group. |
TdExpr.mod | Modulus operator. |
TdExpr.mul | Multiplication operator. |
TdExpr.n_unique | Aggregation operation that counts the unique values of the given column in the group. |
TdExpr.ne | Compare if 2 expressions are not equal, equivalent to expr != other. |
TdExpr.ne_missing | Compare if 2 expressions are not equal an, equivalent to expr != other. |
TdExpr.neg | Unary minus operator. |
TdExpr.not_ | Negate a boolean expression. |
TdExpr.or_ | Bitwise or operator with the given expressions. |
TdExpr.pow | Exponentiation operator. |
TdExpr.radians | Convert a degree value to radians |
TdExpr.rank | Compute the rank of the element values. |
TdExpr.reinterpret | Reinterpret the 64bit element values (i64 or u64) as a signed/unsigned integers. |
TdExpr.round | Round floating point element values. |
TdExpr.round_sig_figs | Round floating point element values to the specified significant figures. |
TdExpr.shrink_dtype | Cast down a column to the smallest type that can hold the element values. |
TdExpr.sign | Calculate the sign of element values. |
TdExpr.sin | Calculate the sine of the element value. |
TdExpr.sinh | Calculate the hyperbolic sine of the element value. |
TdExpr.slice | Compute a slice of the TableFrame for the specified columns. |
TdExpr.sqrt | Calculate the square root of the element value. |
TdExpr.sub | Equivalent to the - operator. |
TdExpr.sum | Aggregation operation that sums the values in the group. |
TdExpr.tan | Calculate the tangent of the element value. |
TdExpr.tanh | Calculate the hyperbolic tangent of the element value. |
TdExpr.truediv | Equivalent to the float / operator. |
TdExpr.xor | Bitwise xor operator with the given expression. |
ErrorCode
class ErrorCode(*args, **kwds)
Bases: Enum
TableFrameError
class TableFrameError(error_code: ErrorCode, *args)
Bases: TabsDataException
Exception raised when handling a (Td)TableFrame.
TdExpr
class TdExpr(expr: Expr | TdExpr)
dtTdExprDateTimeNameSpaceReturn an object namespace with all date-time methods for a date-time value.
strTdExprStringNameSpaceReturn an object namespace with all string methods for a string value.
adddef add(other: Any) -> TdExpr
Equivalent to the + operator.
For numeric types adds the given input. For string types concatenates the given input.
Parameters:
otherThe value to add or concatenate.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("val"), td.col("val").add(1).alias("add"))
>>>
┌──────┬──────────┐
│ val ┆ add │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞══════╪══════════╡
│ 1 ┆ 2 │
│ 15 ┆ 16 │
│ 18 ┆ 19 │
│ 60 ┆ 61 │
│ 60 ┆ 61 │
│ 75 ┆ 76 │
│ null ┆ null │
└──────┴──────────┘
aliasdef alias(name: str) -> TdExpr
Set the name for a column or expression.
Parameters:
nameColumn or expression new name. The name must be a word ([A-Za-z_][A-Za-z0-9_]*) of up to 100 characters.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("age"), td.col("age").alias("Age"))
>>>
┌──────┬──────┐
│ age ┆ Age │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞══════╪══════╡
│ 1 ┆ 1 │
│ 15 ┆ 15 │
│ 18 ┆ 18 │
│ 60 ┆ 60 │
│ 60 ┆ 60 │
│ 75 ┆ 75 │
│ null ┆ null │
└──────┴──────┘
and_def and_(*others: Any) -> TdExpr
Bitwise and operator with the given expressions.
It can be used with integer and bool types.
Parameters:
othersexpressions to peform the bitwise and with.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("i"), td.col("i").and_(2).alias("and_"))
>>>
┌──────┬──────┐
│ i ┆ and_ │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞══════╪══════╡
│ -1 ┆ 2 │
│ 2 ┆ 2 │
│ -3 ┆ 0 │
│ 0 ┆ 0 │
│ 5 ┆ 0 │
│ 7 ┆ 2 │
│ null ┆ null │
└──────┴──────┘
arccosdef arccos() -> TdExpr
Calculate the inverse cosine of the element value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").arccos().alias("arccos"))
>>>
┌──────┬──────────┐
│ val ┆ arccos │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪══════════╡
│ 0.01 ┆ 1.560796 │
│ 0.15 ┆ 1.420228 │
│ 0.18 ┆ 1.38981 │
│ 0.6 ┆ 0.927295 │
│ 0.6 ┆ 0.927295 │
│ 0.75 ┆ 0.722734 │
│ null ┆ null │
└──────┴──────────┘
arccoshdef arccosh() -> TdExpr
Calculate the inverse hyperbolic cosine of the element value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").arccosh().alias("arccosh"))
>>>
┌──────┬──────────┐
│ val ┆ arccosh │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪══════════╡
│ 0.1 ┆ NaN │
│ 1.5 ┆ 0.962424 │
│ 1.8 ┆ 1.192911 │
│ 6.0 ┆ 2.477889 │
│ 6.0 ┆ 2.477889 │
│ 7.5 ┆ 2.703576 │
│ null ┆ null │
└──────┴──────────┘
arcsindef arcsin() -> TdExpr
Calculate the inverse sine of the element value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").arcsin().alias("arcsin"))
>>>
┌──────┬──────────┐
│ val ┆ arcsin │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪══════════╡
│ 0.01 ┆ 0.01 │
│ 0.15 ┆ 0.150568 │
│ 0.18 ┆ 0.180986 │
│ 0.6 ┆ 0.643501 │
│ 0.6 ┆ 0.643501 │
│ 0.75 ┆ 0.848062 │
│ null ┆ null │
└──────┴──────────┘
arcsinhdef arcsinh() -> TdExpr
Calculate the inverse hyperbolic sine of the element value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").arcsinh().alias("arcsinh"))
>>>
┌──────┬──────────┐
│ val ┆ arcsinh │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪══════════╡
│ 0.1 ┆ 0.099834 │
│ 1.5 ┆ 1.194763 │
│ 1.8 ┆ 1.350441 │
│ 6.0 ┆ 2.49178 │
│ 6.0 ┆ 2.49178 │
│ 7.5 ┆ 2.712465 │
│ null ┆ null │
└──────┴──────────┘
arctandef arctan() -> TdExpr
Calculate the inverse tangent of the element value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), , td.col("val").arctan().alias("arctan"))
>>>
┌──────┬──────────┐
│ val ┆ arctan │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪══════════╡
│ 0.01 ┆ 0.01 │
│ 0.15 ┆ 0.14889 │
│ 0.18 ┆ 0.178093 │
│ 0.6 ┆ 0.54042 │
│ 0.6 ┆ 0.54042 │
│ 0.75 ┆ 0.643501 │
│ null ┆ null │
└──────┴──────────┘
arctanhdef arctanh() -> TdExpr
Calculate the inverse hyperbolic tangent of the element value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), , td.col("val").arctanh().alias("arctanh"))
>>>
┌──────┬──────────┐
│ val ┆ arctanh │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪══════════╡
│ 0.01 ┆ 0.01 │
│ 0.15 ┆ 0.15114 │
│ 0.18 ┆ 0.181983 │
│ 0.6 ┆ 0.693147 │
│ 0.6 ┆ 0.693147 │
│ 0.75 ┆ 0.972955 │
│ null ┆ null │
└──────┴──────────┘
castdef cast(
dtype: PolarsDataType | type[Any],
strict: bool = True,
wrap_numerical: bool = False,
) -> TdExpr
Cast a value to d different type.
Parameters:
dtypeThe data type to cast to.
strictIf false, invalid casts produce null's; if true, an excetion is raised.
wrap_numericalIf true, overflowing numbers ara handled; if false, an excetion is raised.
Example:
>>> import tabsdata as td
>>> import polars as pl
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").cast(pl.Float64)).alias("cast")
>>>
┌──────┬──────┐
│ val ┆ cast │
│ --- ┆ --- │
│ i64 ┆ f64 │
╞══════╪══════╡
│ 1 ┆ 1.0 │
│ 15 ┆ 15.0 │
│ 18 ┆ 18.0 │
│ 60 ┆ 60.0 │
│ 60 ┆ 60.0 │
│ 75 ┆ 75.0 │
│ null ┆ null │
└──────┴──────┘
cbrtdef cbrt() -> TdExpr
Calculate the cub root of the element value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").cbrt().alias("cbrt"))
>>>
┌──────┬──────────┐
│ val ┆ cbrt │
│ --- ┆ --- │
│ i64 ┆ f64 │
╞══════╪══════════╡
│ 1 ┆ 1.0 │
│ 15 ┆ 2.466212 │
│ 18 ┆ 2.620741 │
│ 60 ┆ 3.914868 │
│ 60 ┆ 3.914868 │
│ 75 ┆ 4.217163 │
│ null ┆ null │
└──────┴──────────┘
ceildef ceil() -> TdExpr
Round up the expression to the next integer value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("temp"), td.col("temp").first().ceil().alias("ceil"))
>>>
┌──────┬─────────┐
│ temp ┆ ceil │
│ --- ┆ ------- │
│ f64 ┆ f64 │
╞══════╪═════════╡
│ 1.0 ┆ 1.0 │
│ 1.1 ┆ 2.0 │
└──────┴─────────┘
clipdef clip(
lower_bound: NumericLiteral | TemporalLiteral | IntoTdExprColumn | None = None,
upper_bound: NumericLiteral | TemporalLiteral | IntoTdExprColumn | None = None,
) -> TdExpr
For element values outside the lower and upper bounds, lower values are replaced with the lower bound and upper values with the upper bound. Values within the lower and upper bounds are unaffected.
Parameters:
lower_boundThe lower bound value. If None, the lower bound is not set.
upper_boundThe upper bound value. If None, the upper bound is
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("age"), td.col("age").clip(18,65).alias("clip"))
>>>
┌──────┬─────────┐
│ age ┆ clip │
│ --- ┆ ------- │
│ i64 ┆ i64 │
╞══════╪═══+++═══╡
│ 1 ┆ 18 │
│ 18 ┆ 18 │
│ 50 ┆ 50 │
│ 65 ┆ 65 │
│ 70 ┆ 65 │
└──────┴─────────┘
cosdef cos() -> TdExpr
Calculate the cosine of the element value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").cos().alias("cos"))
>>>
┌──────┬───────────┐
│ val ┆ cos │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪═══════════╡
│ 0.1 ┆ 0.995004 │
│ 1.5 ┆ 0.070737 │
│ 1.8 ┆ -0.227202 │
│ 6.0 ┆ 0.96017 │
│ 6.0 ┆ 0.96017 │
│ 7.5 ┆ 0.346635 │
│ null ┆ null │
└──────┴───────────┘
coshdef cosh() -> TdExpr
Calculate the hyperbolic cosine of the element value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").cosh().alias("cosh"))
>>>
┌──────┬────────────┐
│ val ┆ cosh │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪════════════╡
│ 0.1 ┆ 1.005004 │
│ 1.5 ┆ 2.35241 │
│ 1.8 ┆ 3.107473 │
│ 6.0 ┆ 201.715636 │
│ 6.0 ┆ 201.715636 │
│ 7.5 ┆ 904.021484 │
│ null ┆ null │
└──────┴────────────┘
cotdef cot() -> TdExpr
Calculate the cotangent of the element value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").cot().alias("cot"))
>>>
┌──────┬───────────┐
│ val ┆ cot │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪═══════════╡
│ 0.1 ┆ 9.966644 │
│ 1.5 ┆ 0.070915 │
│ 1.8 ┆ -0.233304 │
│ 6.0 ┆ -3.436353 │
│ 6.0 ┆ -3.436353 │
│ 7.5 ┆ 0.369547 │
│ null ┆ null │
└──────┴───────────┘
countdef count() -> TdExpr
Aggregation operation that counts the non null values of the given column in
the group.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ a ┆ b │
│ --- ┆ --- │
│ str ┆ i64 │
╞══════╪══════╡
│ A ┆ 1 │
│ B ┆ 2 │
│ A ┆ 3 │
│ B ┆ 0 │
│ C ┆ 5 │
│ null ┆ 6 │
│ C ┆ null │
└──────┴──────┘
>>>
>>> tf.group_by(td.col("a")).agg(td.col("b")).count().alias("count"))
>>>
┌──────┬───────┐
│ a ┆ count │
│ --- ┆ --- │
│ str ┆ u32 │
╞══════╪═══════╡
│ null ┆ 1 │
│ A ┆ 2 │
│ B ┆ 2 │
│ C ┆ 1 │
└──────┴───────┘
degreesdef degrees() -> TdExpr
Convert a radian value to degrees
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").degrees().alias("degrees"))
>>>
┌──────┬────────────┐
│ val ┆ degress │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪════════════╡
│ 0.1 ┆ 5.729578 │
│ 1.5 ┆ 85.943669 │
│ 1.8 ┆ 103.132403 │
│ 6.0 ┆ 343.774677 │
│ 6.0 ┆ 343.774677 │
│ 7.5 ┆ 429.718346 │
│ null ┆ null │
└──────┴────────────┘
diffdef diff(n: int = 1) -> TdExpr
Compute the difference between an element value and the element value of the specified relative row.
It supports numberic and datetime types.
Parameters:
nThe relative row to compute the difference with. Defaults to 1 (previous). Use a negative number to get a next row.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("i"), td.col("i").diff().diff().alias("diff"))
>>>
┌──────┬──────┐
│ i ┆ diff │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞══════╪══════╡
│ 1 ┆ null │
│ 0 ┆ -1 │
│ 2 ┆ 2 │
│ 3 ┆ 1 │
│ 4 ┆ 1 │
│ -1 ┆ -5 │
│ -2 ┆ -1 │
│ -3 ┆ -1 │
│ -4 ┆ -1 │
│ -5 ┆ -1 │
│ null ┆ null │
└──────┴──────┘
eqdef eq(other: Any) -> TdExpr
Compare if 2 expressions are equal, equivalent to expr == other. If one
of the expressions is null (None) it returns null.
Parameters:
otherThe value to compare with.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("a").eq(td.col("b")).alias("eq"))
>>>
┌─────┬──────┬───────┐
│ a ┆ b ┆ eq │
│ --- ┆ --- ┆ --- │
│ f64 ┆ f64 ┆ bool │
╞═════╪══════╪═══════╡
│ 1.0 ┆ 2.0 ┆ false │
│ 2.0 ┆ 2.0 ┆ true │
│ NaN ┆ NaN ┆ true │
│ 4.0 ┆ NaN ┆ false │
│ 5.0 ┆ null ┆ null │
│ null┆ null ┆ null │
└─────┴──────┴───────┘
eq_missingdef eq_missing(other: Any) -> TdExpr
Compare if 2 expressions are equal an, equivalent to expr == other. If one
of the expressions is null (None) it returns false.
Parameters:
otherThe value to compare with.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("a").eq(td.col("b")).alias("eq_missing"))
>>>
┌─────┬──────┬───────────┐
│ a ┆ b ┆ eq_missing│
│ --- ┆ --- ┆ --- │
│ f64 ┆ f64 ┆ bool │
╞═════╪══════╪═══════════╡
│ 1.0 ┆ 2.0 ┆ false │
│ 2.0 ┆ 2.0 ┆ true │
│ NaN ┆ NaN ┆ true │
│ 4.0 ┆ NaN ┆ false │
│ 5.0 ┆ null ┆ false │
│ null┆ null ┆ true │
└─────┴──────┴───────────┘
expdef exp() -> TdExpr
Calculate the exponential of the element value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").exp().alias("exp"))
>>>
┌──────┬─────────────┐
│ val ┆ exp │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪═════════════╡
│ 0.1 ┆ 1.105171 │
│ 6.0 ┆ 403.428793 │
│ 6.0 ┆ 403.428793 │
│ 7.5 ┆ 1808.042414 │
│ null ┆ null │
└──────┴─────────────┘
fill_nandef fill_nan(value: int | float | TdExpr | None) -> TdExpr
Replace NaN values with the given value.
Parameters:
valueThe value to replace NaN values with.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").fill_nan(5.5)
>>> .alias("fill_nan"))
>>>
┌──────┬──────────┐
│ val ┆ fill_nan │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪══════════╡
│ 1.1 ┆ 1.1 │
│ 2.0 ┆ 2.0 │
│ inf ┆ inf │
│ null ┆ null │
│ NaN ┆ 5.5 │
└──────┴──────────┘
fill_nulldef fill_null(
value: Any | TdExpr | None = None,
strategy: FillNullStrategy | None = None,
limit: int | None = None,
) -> TdExpr
Replace null values with the given value.
Parameters:
valueThe value to replace null values with.
strategyThe strategy to use for filling null values.
limitThe maximum number of null values to replace.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val")
>>> .fill_null(5.5).alias("fill_null"))
>>>
┌──────┬───────────┐
│ val ┆ fill_null │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪═══════════╡
│ -1.0 ┆ -1.0 │
│ 0.0 ┆ 0.0 │
│ 1.1 ┆ 1.1 │
│ 2.0 ┆ 2.0 │
│ inf ┆ inf │
│ null ┆ 5.5 │
│ NaN ┆ NaN │
└──────┴───────────┘
filterdef filter(*predicates: IntoTdExprColumn | Iterable[IntoTdExprColumn]) -> TdExpr
Apply a filter predicate to an expression.
Elements for which the predicate does not evaluate to true are discarded,
evaluations to null are also discarded.
Useful in an aggregation expression.
Parameters:
predicatesExpression(s) that evaluates to a boolean.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌───────┬─────────┐
│ state ┆ tickets │
│ --- ┆ --- │
│ str ┆ i64 │
╞═══════╪═════════╡
│ CA ┆ 1 │
│ AL ┆ 3 │
│ CA ┆ 2 │
│ NY ┆ 2 │
│ NY ┆ 3 │
└───────┴─────────┘
>>>
>>> import tabsdata as td
>>> tf.group_by("state").agg(td.col("tickets")
>>> .filter(td.col("tickets") !=2)
>>> .sum().alias("sum_non_two"))
>>>
┌───────┬─────────────┐
│ state ┆ sum_non_two │
│ --- ┆ --- │
│ str ┆ i64 │
╞═══════╪═════════════╡
│ AL ┆ 3 │
│ NY ┆ 3 │
│ CA ┆ 1 │
└───────┴─────────────┘
firstdef first() -> TdExpr
Get the first element.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("age"), td.col("age").first().alias("first"))
>>>
┌──────┬─────────┐
│ age ┆ first │
│ --- ┆ ------- │
│ i64 ┆ i64 │
╞══════╪═════════╡
│ 10 ┆ 10 │
│ 11 ┆ 10 │
│ 18 ┆ 10 │
│ 65 ┆ 10 │
│ 70 ┆ 10 │
└──────┴─────────┘
floordef floor() -> TdExpr
Round down the expression to the previous integer value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("temp"), td.col("temp").ceil().alias("floor"))
>>>
┌──────┬─────────┐
│ temp ┆ floor │
│ --- ┆ ------- │
│ f64 ┆ i64 │
╞══════╪═════════╡
│ 1.0 ┆ 1 │
│ 1.1 ┆ 1 │
└──────┴─────────┘
floordivdef floordiv(other: Any) -> TdExpr
Calculate the floor on the division.
Parameters:
otherThe value to divide by.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("temp"), td.col("temp").floordiv(2)
>>> .alias("floordiv"))
>>>
┌──────┬──────────┐
│ temp ┆ floordiv │
│ --- ┆ ------- │
│ f64 ┆ i64 │
╞══════╪══════════╡
│ 2.5 ┆ 1 │
│ 1.4 ┆ 0 │
└──────┴──────────┘
gedef ge(other: Any) -> TdExpr
Greater or equal operator.
Parameters:
otherThe value to compare with.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("temp"), td.col("temp").ge(1.0).alias("ge"))
>>>
┌──────┬─────────┐
│ temp ┆ ge │
│ --- ┆ ------- │
│ f64 ┆ bool │
╞══════╪═════════╡
│ 0.9 ┆ false │
│ 1.1 ┆ true │
└──────┴─────────┘
gtdef gt(other: Any) -> TdExpr
Greater than operator.
Parameters:
otherThe value to compare with.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("temp"), td.col("temp").gt(1.0).alias("gt"))
>>>
┌──────┬─────────┐
│ temp ┆ ge │
│ --- ┆ ------- │
│ f64 ┆ bool │
╞══════╪═════════╡
│ 1.0 ┆ false │
│ 1.1 ┆ true │
└──────┴─────────┘
hashdef hash(
seed: int = 0,
seed_1: int | None = None,
seed_2: int | None = None,
seed_3: int | None = None,
) -> TdExpr
Compute the hash of an element value.
Parameters:
seedThe seed for the hash function.
seed_1The first seed for the hash function.
seed_2The second seed for the hash function.
seed_3The third seed for the hash function.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("temp"), td.col("temp").hash(5).alias("hash"))
>>>
┌──────┬─────────────────────┐
│ temp ┆ hash │
│ --- ┆ --- │
│ f64 ┆ u64 │
╞══════╪═════════════════════╡
│ 1.1 ┆ 1438840365631752616 │
│ 2.0 ┆ 4738789230185236462 │
└──────┴─────────────────────┘
is_betweendef is_between(
lower_bound: IntoTdExpr,
upper_bound: IntoTdExpr,
closed: ClosedInterval = 'both',
) -> TdExpr
If an expression is between the given bounds.
Parameters:
lower_boundThe lower bound value.
upper_boundThe upper bound value.
closedThe interval type, either "both", "left", "right", or "neither"
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("temp"), td.col("temp")
>>> .is_between(0, 1).alias("between"))
>>>
┌──────┬─────────┐
│ temp ┆ between │
│ --- ┆ ------- │
│ f64 ┆ bool │
╞══════╪═════════╡
│-1.0 ┆ false │
│ 0.0 ┆ true │
│ 0.5 ┆ true │
│ 1.0 ┆ true │
│ 1.1 ┆ false │
└──────┴─────────┘
is_finitedef is_finite() -> TdExpr
If an element value is finite.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("temp"), td.col("temp").is_finite()
>>> .alias("finite"))
>>>
┌──────┬────────┐
│ temp ┆ finite │
│ --- ┆ --- │
│ f64 ┆ bool │
╞══════╪════════╡
│ 1.1 ┆ true │
│ 2.0 ┆ true │
│ inf ┆ false │
└──────┴────────┘
is_indef is_in(other: TdExpr | Collection[Any] | Series) -> TdExpr
If an element value is in the given collection.
Parameters:
otherThe collection to check if the element value is in.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("temp"), td.col("temp").is_in([1.1, 2.2])
>>> .alias("is_in"))
>>>
┌──────┬────────┐
│ temp ┆ is_in │
│ --- ┆ --- │
│ f64 ┆ bool │
╞══════╪════════╡
│ 1.1 ┆ true │
│ 2.0 ┆ false │
│ inf ┆ false │
└──────┴────────┘
is_infinitedef is_infinite() -> TdExpr
If an element value is infinite.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("temp"), td.col("temp")
>>> .is_infinite().alias("infinite"))
>>>
┌──────┬──────────┐
│ temp ┆ infinite │
│ --- ┆ --- │
│ f64 ┆ bool │
╞══════╪══════════╡
│ 1.1 ┆ false │
│ 2.0 ┆ false │
│ inf ┆ true │
└──────┴──────────┘
is_nandef is_nan() -> TdExpr
If an element value is NaN.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("temp"), td.col("temp").is_nan().alias("nan"))
>>>
┌──────┬──────────┐
│ temp ┆ nan │
│ --- ┆ --- │
│ f64 ┆ bool │
╞══════╪══════════╡
│ 1.1 ┆ false │
│ Nan ┆ true │
│ None ┆ false │
│ inf ┆ false │
└──────┴──────────┘
is_not_nandef is_not_nan() -> TdExpr
If an element value is not NaN.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("temp"), td.col("temp").is_not_nan()
>>> .alias("not_nan"))
>>>
┌──────┬──────────┐
│ temp ┆ not_nan │
│ --- ┆ --- │
│ f64 ┆ bool │
╞══════╪══════════╡
│ 1.1 ┆ true │
│ Nan ┆ false │
│ None ┆ false │
│ inf ┆ true │
└──────┴──────────┘
is_not_nulldef is_not_null() -> TdExpr
If an element value is not null (None).
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("temp"), td.col("temp").is_not_null()
>>> .alias("null"))
>>>
┌──────┬──────────┐
│ temp ┆ not_nulL │
│ --- ┆ --- │
│ f64 ┆ bool │
╞══════╪══════════╡
│ 1.1 ┆ true │
│ Nan ┆ true │
│ None ┆ false │
│ inf ┆ true │
└──────┴──────────┘
is_nulldef is_null() -> TdExpr
If an element value is null (None).
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("temp"), td.col("temp").is_not_null()
>>> .alias("null"))
>>>
┌──────┬──────────┐
│ temp ┆ null │
│ --- ┆ --- │
│ f64 ┆ bool │
╞══════╪══════════╡
│ 1.1 ┆ false │
│ Nan ┆ false │
│ None ┆ true │
│ inf ┆ false │
└──────┴──────────┘
is_uniquedef is_unique() -> TdExpr
If an element value is unique for all values in the column.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("temp"), td.col("temp").is_unique()
>>> .alias("unique"))
>>>
┌──────┬──────────┐
│ temp ┆ unique │
│ --- ┆ --- │
│ f64 ┆ bool │
╞══════╪══════════╡
│ 1.1 ┆ false │
│ 1.1 ┆ false │
│ None ┆ true │
│ 2.0 ┆ true │
└──────┴──────────┘
lastdef last() -> TdExpr
Get the last element.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("age"), td.col("age").first().alias("last"))
>>>
┌──────┬─────────┐
│ age ┆ last │
│ --- ┆ ------- │
│ i64 ┆ i64 │
╞══════╪═════════╡
│ 10 ┆ 70 │
│ 11 ┆ 70 │
│ 18 ┆ 70 │
│ 65 ┆ 70 │
│ 70 ┆ 70 │
└──────┴─────────┘
ledef le(other: Any) -> TdExpr
Less or equal operator.
Parameters:
otherThe value to compare with.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("temp"), td.col("temp").le(1.0).alias("le"))
>>>
┌──────┬─────────┐
│ temp ┆ le │
│ --- ┆ ------- │
│ f64 ┆ bool │
╞══════╪═════════╡
│ 0.9 ┆ true │
│ 1.1 ┆ false │
└──────┴─────────┘
lendef len() -> TdExpr
Aggregation operation that counts the rows in the group.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ a ┆ b │
│ --- ┆ --- │
│ str ┆ i64 │
╞══════╪══════╡
│ A ┆ 1 │
│ B ┆ 2 │
│ A ┆ 3 │
│ B ┆ 0 │
│ C ┆ 5 │
│ null ┆ 6 │
│ C ┆ null │
└──────┴──────┘
>>>
>>> tf.group_by(td.col("a")).agg(td.col("b")).len().alias("len"))
>>>
┌──────┬─────┐
│ a ┆ len │
│ --- ┆ --- │
│ str ┆ u32 │
╞══════╪═════╡
│ null ┆ 1 │
│ A ┆ 2 │
│ B ┆ 2 │
│ C ┆ 2 │
└──────┴─────┘
logdef log(base: float = 2.718281828459045) -> TdExpr
Calculate the logarithm to the given base.
Parameters:
baselogarithm base, defaults to e.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").log().alias("log")
>>>
┌──────┬──────────┐
│ val ┆ log │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪══════════╡
│ -1.0 ┆ NaN │
│ 0.0 ┆ -inf │
│ 1.1 ┆ 0.09531 │
│ 2.0 ┆ 0.693147 │
│ inf ┆ inf │
│ null ┆ null │
│ NaN ┆ NaN │
└──────┴──────────┘
log10def log10() -> TdExpr
Calculate the logarithm base 10.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").log10().alias("log10")
>>>
┌──────┬──────────┐
│ val ┆ log10 │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪══════════╡
│ -1.0 ┆ NaN │
│ 0.0 ┆ -inf │
│ 1.1 ┆ 0.041393 │
│ 2.0 ┆ 0.30103 │
│ inf ┆ inf │
│ null ┆ null │
│ NaN ┆ NaN │
└──────┴──────────┘
log1pdef log1p() -> TdExpr
Calculate the natural logarithm plus one.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").log1p().alias("log1p")
>>>
┌──────┬──────────┐
│ val ┆ log1p │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪══════════╡
│ -1.0 ┆ -inf │
│ 0.0 ┆ 0.0 │
│ 1.1 ┆ 0.741937 │
│ 2.0 ┆ 1.098612 │
│ inf ┆ inf │
│ null ┆ null │
│ NaN ┆ NaN │
└──────┴──────────┘
ltdef lt(other: Any) -> TdExpr
Less than operator.
Parameters:
otherThe value to compare with.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").lt(1.0).alias("lt"))
>>>
┌──────┬─────────┐
│ val ┆ tl │
│ --- ┆ ------- │
│ f64 ┆ bool │
╞══════╪═════════╡
│ 1.0 ┆ false │
│ 0.1 ┆ true │
└──────┴─────────┘
maxdef max() -> TdExpr
Aggregation operation that finds the maximum value in the group.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ ss ┆ i │
│ --- ┆ --- │
│ str ┆ i64 │
╞══════╪══════╡
│ A ┆ 1 │
│ B ┆ 0 │
│ A ┆ 2 │
│ B ┆ 3 │
│ B ┆ 4 │
│ C ┆ -1 │
│ C ┆ -2 │
│ C ┆ -3 │
│ D ┆ -4 │
│ F ┆ -5 │
│ null ┆ null │
└──────┴──────┘
>>>
>>> tf.group_by(td.col("a")).agg(td.col("b")).max())
>>>
┌──────┬──────┐
│ ss ┆ i │
│ --- ┆ --- │
│ str ┆ i64 │
╞══════╪══════╡
│ F ┆ -5 │
│ C ┆ -1 │
│ A ┆ 2 │
│ B ┆ 4 │
│ D ┆ -4 │
│ null ┆ null │
└──────┴──────┘
meandef mean() -> TdExpr
Aggregation operation that finds the mean of the values in the group.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ ss ┆ i │
│ --- ┆ --- │
│ str ┆ i64 │
╞══════╪══════╡
│ A ┆ 1 │
│ B ┆ 0 │
│ A ┆ 2 │
│ B ┆ 3 │
│ B ┆ 4 │
│ C ┆ -1 │
│ C ┆ -2 │
│ C ┆ -3 │
│ D ┆ -4 │
│ F ┆ -5 │
│ null ┆ null │
└──────┴──────┘
>>>
>>> tf.group_by(td.col("a")).agg(td.col("b")).mean())
>>>
┌──────┬──────────┐
│ ss ┆ i │
│ --- ┆ --- │
│ str ┆ f64 │
╞══════╪══════════╡
│ null ┆ null │
│ A ┆ 1.5 │
│ F ┆ -5.0 │
│ C ┆ -2.0 │
│ D ┆ -4.0 │
│ B ┆ 2.333333 │
└──────┴──────────┘
mediandef median() -> TdExpr
Aggregation operation that finds the median of the values in the group.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ ss ┆ i │
│ --- ┆ --- │
│ str ┆ i64 │
╞══════╪══════╡
│ A ┆ 1 │
│ B ┆ 0 │
│ A ┆ 2 │
│ B ┆ 3 │
│ B ┆ 4 │
│ C ┆ -1 │
│ C ┆ -2 │
│ C ┆ -3 │
│ D ┆ -4 │
│ F ┆ -5 │
│ null ┆ null │
└──────┴──────┘
>>>
>>> tf.group_by(td.col("a")).agg(td.col("b")).median())
>>>
┌──────┬──────┐
│ ss ┆ i │
│ --- ┆ --- │
│ str ┆ f64 │
╞══════╪══════╡
│ F ┆ -5.0 │
│ C ┆ -2.0 │
│ B ┆ 3.0 │
│ D ┆ -4.0 │
│ A ┆ 1.5 │
│ null ┆ null │
└──────┴──────┘
mindef min() -> TdExpr
Aggregation operation that finds the minimum value in the group.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ ss ┆ i │
│ --- ┆ --- │
│ str ┆ i64 │
╞══════╪══════╡
│ A ┆ 1 │
│ B ┆ 0 │
│ A ┆ 2 │
│ B ┆ 3 │
│ B ┆ 4 │
│ C ┆ -1 │
│ C ┆ -2 │
│ C ┆ -3 │
│ D ┆ -4 │
│ F ┆ -5 │
│ null ┆ null │
└──────┴──────┘
>>>
>>> tf.group_by(td.col("a")).agg(td.col("b")).min())
>>>
┌──────┬──────┐
│ ss ┆ i │
│ --- ┆ --- │
│ str ┆ i64 │
╞══════╪══════╡
│ C ┆ -3 │
│ A ┆ 1 │
│ null ┆ null │
│ B ┆ 0 │
│ F ┆ -5 │
│ D ┆ -4 │
└──────┴──────┘
moddef mod(other: Any) -> TdExpr
Modulus operator.
Parameters:
otherThe value to divide by.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").mod(5).alias("mod"))
>>>
┌──────┬──────┐
│ val ┆ mod │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞══════╪══════╡
│ 1 ┆ 1 │
│ 15 ┆ 0 │
│ 18 ┆ 3 │
│ null ┆ null │
└──────┴──────┘
muldef mul(other: Any) -> TdExpr
Multiplication operator.
Parameters:
otherThe value to multiply by.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").mul(10).alias("mul"))
>>>
┌──────┬──────┐
│ val ┆ mul │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞══════╪══════╡
│ 1 ┆ 10 │
│ 15 ┆ 150 │
│ 18 ┆ 180 │
│ 75 ┆ 750 │
│ null ┆ null │
└──────┴──────┘
n_uniquedef n_unique() -> TdExpr
Aggregation operation that counts the unique values of the given column in the group.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ ss ┆ i │
│ --- ┆ --- │
│ str ┆ i64 │
╞══════╪══════╡
│ A ┆ 1 │
│ B ┆ 0 │
│ A ┆ 2 │
│ B ┆ 3 │
│ B ┆ 4 │
│ C ┆ -1 │
│ C ┆ -2 │
│ C ┆ -3 │
│ D ┆ -4 │
│ F ┆ -5 │
│ null ┆ null │
└──────┴──────┘
>>>
>>> tf.group_by(td.col("a")).agg(td.col("b")).n_unique())
>>>
┌──────┬─────┐
│ ss ┆ i │
│ --- ┆ --- │
│ str ┆ u32 │
╞══════╪═════╡
│ D ┆ 1 │
│ C ┆ 3 │
│ A ┆ 2 │
│ B ┆ 3 │
│ F ┆ 1 │
│ null ┆ 1 │
└──────┴─────┘
nedef ne(other: Any) -> TdExpr
Compare if 2 expressions are not equal, equivalent to expr != other. If one
of the expressions is null (None) it returns null.
Parameters:
otherThe value to compare with.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("a").ne(td.col("b")).alias("ne"))
>>>
┌─────┬──────┬───────┐
│ a ┆ b ┆ ne │
│ --- ┆ --- ┆ --- │
│ f64 ┆ f64 ┆ bool │
╞═════╪══════╪═══════╡
│ 1.0 ┆ 2.0 ┆ true │
│ 2.0 ┆ 2.0 ┆ false │
│ NaN ┆ NaN ┆ false │
│ 4.0 ┆ NaN ┆ true │
│ 5.0 ┆ null ┆ null │
│ null┆ null ┆ null │
└─────┴──────┴───────┘
ne_missingdef ne_missing(other: Any) -> TdExpr
Compare if 2 expressions are not equal an, equivalent to expr != other. If one
of the expressions is null (None) it returns false.
Parameters:
otherThe value to compare with.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("a").eq(td.col("b")).alias("ne_missing"))
>>>
┌─────┬──────┬───────────┐
│ a ┆ b ┆ ne_missing│
│ --- ┆ --- ┆ --- │
│ f64 ┆ f64 ┆ bool │
╞═════╪══════╪═══════════╡
│ 1.0 ┆ 2.0 ┆ true │
│ 2.0 ┆ 2.0 ┆ false │
│ NaN ┆ NaN ┆ false │
│ 4.0 ┆ NaN ┆ true │
│ 5.0 ┆ null ┆ true │
│ null┆ null ┆ false │
└─────┴──────┴───────────┘
negdef neg() -> TdExpr
Unary minus operator.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").neg().alias("neg"))
>>>
┌──────┬──────┐
│ val ┆ neg │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪══════╡
│ -1.0 ┆ 1.0 │
│ 0.0 ┆ -0.0 │
│ 1.1 ┆ -1.1 │
│ 2.0 ┆ -2.0 │
│ inf ┆ -inf │
│ null ┆ null │
│ NaN ┆ NaN │
└──────┴──────┘
not_def not_() -> TdExpr
Negate a boolean expression.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").not_().alias("not"))
>>>
┌───────┬───────┐
│ val ┆ not │
│ --- ┆ --- │
│ bool ┆ bool │
╞═══════╪═══════╡
│ true ┆ false │
│ false ┆ true │
│ null ┆ null │
└───────┴───────┘
or_def or_(*others: Any) -> TdExpr
Bitwise or operator with the given expressions.
It can be used with integer and bool types.
Parameters:
othersexpressions to peform the bitwise or with.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").or_(1).alias("or"))
>>>
┌──────┬──────┐
│ val ┆ or │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞══════╪══════╡
│ 1 ┆ 1 │
│ 15 ┆ 15 │
│ 18 ┆ 19 │
│ 60 ┆ 61 │
│ null ┆ null │
└──────┴──────┘
powdef pow(exponent: IntoTdExprColumn | int | float) -> TdExpr
Exponentiation operator.
Parameters:
exponentexponent value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").pow(2).alias("pow"))
>>>
┌──────┬──────┐
│ age ┆ pow │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞══════╪══════╡
│ 1 ┆ 1 │
│ 15 ┆ 225 │
│ 18 ┆ 324 │
│ 60 ┆ 3600 │
│ null ┆ null │
└──────┴──────┘
radiansdef radians() -> TdExpr
Convert a degree value to radians
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf = tf.select(td.col("val"), td.col("val").radians().alias("radians"))
>>>
┌─────────┬──────────┐
│ val ┆ radians │
│ --- ┆ --- │
│ i64 ┆ f64 │
╞═════════╪══════════╡
│ 1 ┆ 0.017453 │
│ 15 ┆ 0.261799 │
│ 60 ┆ 1.047198 │
│ 75 ┆ 1.308997 │
│ null ┆ null │
└─────────┴──────────┘
rankdef rank(
method: RankMethod = 'average',
descending: bool = False,
seed: int | None = None,
) -> TdExpr
Compute the rank of the element values. Multiple rank types are available.
Parameters:
methodthe ranking type: 'average' (default), 'dense', 'max', 'min', 'ordinal' or 'random'.
descendingif the order is ascending (default) or descending.
seedrandom seed when using 'random' rank type.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("val"), td.col("val").rank("max").alias("rank"))
>>>
┌──────┬──────┐
│ val ┆ rank │
│ --- ┆ --- │
│ f64 ┆ u32 │
╞══════╪══════╡
│ -1.0 ┆ 1 │
│ 0.0 ┆ 2 │
│ 1.1 ┆ 3 │
│ 2.0 ┆ 4 │
│ inf ┆ 5 │
│ null ┆ null │
│ NaN ┆ 6 │
└──────┴──────┘
reinterpretdef reinterpret(signed: bool = True) -> TdExpr
Reinterpret the 64bit element values (i64 or u64) as a signed/unsigned integers. Only valid for 64bit integers, for other types use cast.
Parameters:
signedtrue to convert to i64, false to convert to u64. This named argument must be specified.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("val"), td.col("val")
>>> .reinterpret(signed=False).alias("reinterpret"))
>>>
┌──────┬─────────────┐
│ val ┆ reinterpret │
│ --- ┆ --- │
│ i64 ┆ u64 │
╞══════╪═════════════╡
│ 3 ┆ 3 │
│ 1 ┆ 1 │
│ 5 ┆ 5 │
│ 4 ┆ 4 │
│ 2 ┆ 2 │
│ 6 ┆ 6 │
│ null ┆ null │
└──────┴─────────────┘
rounddef round(decimals: int = 0) -> TdExpr
Round floating point element values.
Parameters:
decimalsnumber of decimal places to round to.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("val"), td.col("val").round().alias("round"))
>>>
┌──────┬───────┐
│ val ┆ round │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪═══════╡
│ -1.0 ┆ -1.0 │
│ 0.0 ┆ 0.0 │
│ 1.1 ┆ 1.0 │
│ 2.0 ┆ 2.0 │
│ inf ┆ inf │
│ null ┆ null │
│ NaN ┆ NaN │
└──────┴───────┘
round_sig_figsdef round_sig_figs(digits: int) -> TdExpr
Round floating point element values to the specified significant figures.
Parameters:
digitsnumber of digits to round up.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("val"), td.col("val").round_sig_figs(2)
>>> .alias("round_sig_figs"))
>>>
┌────────┬────────────────┐
│ val ┆ round_sig_figs │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞════════╪════════════════╡
│ 0.0123 ┆ 0.012 │
│ 2.0244 ┆ 2.0 │
│ 0.0 ┆ 0.0 │
│ inf ┆ NaN │
│ 50.0 ┆ 50.0 │
│ 1.0 ┆ 1.0 │
│ NaN ┆ NaN │
│ null ┆ null │
│ 112.0 ┆ 110.0 │
│ 2142.0 ┆ 2100.0 │
└────────┴────────────────┘
shrink_dtypedef shrink_dtype() -> TdExpr
Cast down a column to the smallest type that can hold the element values.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("val"), td.col("val").shrink_dtype()
>>> .alias("shrink_dtype"))
>>>
┌───────┬──────────────┐
│ val ┆ shrink_dtype │
│ --- ┆ --- │
│ i64 ┆ i32 │
╞═══════╪══════════════╡
│ 0 ┆ 0 │
│ 256 ┆ 256 │
│ 65025 ┆ 65025 │
└───────┴──────────────┘
signdef sign() -> TdExpr
Calculate the sign of element values.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("val"), td.col("val").sign().alias("sign"))
>>>
┌────────┬──────┐
│ val ┆ sign │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞════════╪══════╡
│ 0.0123 ┆ 1.0 │
│ 2.0244 ┆ 1.0 │
│ 0.0 ┆ 0.0 │
│ inf ┆ 1.0 │
│ -50.0 ┆ -1.0 │
│ 1.0 ┆ 1.0 │
│ NaN ┆ NaN │
│ null ┆ null │
│ -112.0 ┆ -1.0 │
│ 2142.0 ┆ 1.0 │
└────────┴──────┘
sindef sin() -> TdExpr
Calculate the sine of the element value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("val"), td.col("val").sin().alias("sin"))
>>>
┌─────┬───────────┐
│ val ┆ sin │
│ --- ┆ --- │
│ i64 ┆ f64 │
╞═════╪═══════════╡
│ 0 ┆ 0.0 │
│ 30 ┆ -0.988032 │
│ 60 ┆ -0.304811 │
│ 90 ┆ 0.893997 │
└─────┴───────────┘
sinhdef sinh() -> TdExpr
Calculate the hyperbolic sine of the element value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("val"), td.col("val").sinh().alias("sinh"))
>>>
┌─────┬───────────┐
│ val ┆ sinh │
│ --- ┆ --- │
│ i64 ┆ f64 │
╞═════╪═══════════╡
│ 0 ┆ 0.0 │
│ 30 ┆ 5.3432e12 │
│ 60 ┆ 5.7100e25 │
│ 90 ┆ 6.1020e38 │
└─────┴───────────┘
slicedef slice(offset: int | TdExpr, length: int | TdExpr | None = None) -> TdExpr
Compute a slice of the TableFrame for the specified columns.
Parameters:
offsetthe offset to start the slice.
lengththe length of the slice.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ x ┆ y │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪══════╡
│ 1.0 ┆ 2.0 │
│ 2.0 ┆ 2.0 │
│ NaN ┆ NaN │
│ 4.0 ┆ NaN │
│ 5.0 ┆ null │
│ null ┆ null │
└──────┴──────┘
>>>
>>> tf.select(tf.all().slice(1,2))
>>>
┌─────┬─────┐
│ x ┆ y │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞═════╪═════╡
│ 2.0 ┆ 2.0 │
│ NaN ┆ NaN │
└─────┴─────┘
sqrtdef sqrt() -> TdExpr
Calculate the square root of the element value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("val"), td.col("val").sqrt().alias("sqrt"))
>>>
┌──────┬──────────┐
│ val ┆ sqrt │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪══════════╡
│ 1.0 ┆ 1.0 │
│ 2.0 ┆ 1.414214 │
│ NaN ┆ NaN │
│ 4.0 ┆ 2.0 │
│ 5.0 ┆ 2.236068 │
│ null ┆ null │
└──────┴──────────┘
subdef sub(other: Any) -> TdExpr
Equivalent to the - operator.
Parameters:
othervalue to subtract.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("val"), td.col("val").sub(1).alias("sub"))
>>>
┌──────┬──────────┐
│ val ┆ sub │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞══════╪══════════╡
│ 1 ┆ 0 │
│ 15 ┆ 14 │
│ 18 ┆ 17 │
│ 60 ┆ 59 │
│ 60 ┆ 59 │
│ 75 ┆ 74 │
│ null ┆ null │
└──────┴──────────┘
sumdef sum() -> TdExpr
Aggregation operation that sums the values in the group.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ ss ┆ i │
│ --- ┆ --- │
│ str ┆ i64 │
╞══════╪══════╡
│ A ┆ 1 │
│ B ┆ 0 │
│ A ┆ 2 │
│ B ┆ 3 │
│ B ┆ 4 │
│ C ┆ -1 │
│ C ┆ -2 │
│ C ┆ -3 │
│ D ┆ -4 │
│ F ┆ -5 │
│ null ┆ null │
└──────┴──────┘
>>>
>>> tf.group_by(td.col("a")).agg(td.col("b")).sum())
>>>
┌──────┬─────┐
│ ss ┆ i │
│ --- ┆ --- │
│ str ┆ i64 │
╞══════╪═════╡
│ null ┆ 0 │
│ A ┆ 3 │
│ B ┆ 7 │
│ C ┆ -6 │
│ D ┆ -4 │
│ F ┆ -5 │
└──────┴─────┘
tandef tan() -> TdExpr
Calculate the tangent of the element value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("val"), td.col("val").tan().alias("tan"))
>>>
┌─────┬───────────┐
│ val ┆ tan │
│ --- ┆ --- │
│ i64 ┆ f64 │
╞═════╪═══════════╡
│ 0 ┆ 0.0 │
│ 30 ┆ -6.405331 │
│ 60 ┆ 0.32004 │
│ 90 ┆ -1.9952 │
└─────┴───────────┘
tanhdef tanh() -> TdExpr
Calculate the hyperbolic tangent of the element value.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("val"), td.col("val").tanh().alias("tanh"))
>>>
┌─────┬──────────┐
│ val ┆ tanh │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞═════╪══════════╡
│ 0.0 ┆ 0.0 │
│ 3.0 ┆ 0.995055 │
│ 6.0 ┆ 0.999988 │
│ 9.0 ┆ 1.0 │
└─────┴──────────┘
truedivdef truediv(other: Any) -> TdExpr
Equivalent to the float / operator.
Parameters:
othervalue to divide by.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("val"), td.col("val").truediv(3).alias("truediv"))
>>>
┌────────┬────────────┐
│ val ┆ truediv │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞════════╪════════════╡
│ 0.0123 ┆ 0.0041 │
│ 2.0244 ┆ 0.6748 │
│ 0.0 ┆ 0.0 │
│ inf ┆ inf │
│ -50.0 ┆ -16.666667 │
│ 1.0 ┆ 0.333333 │
│ NaN ┆ NaN │
│ null ┆ null │
│ -112.0 ┆ -37.333333 │
│ 2142.0 ┆ 714.0 │
└────────┴────────────┘
xordef xor(other: Any) -> TdExpr
Bitwise xor operator with the given expression.
It can be used with integer and bool types.
Parameters:
otherexpression to peform the bitwise xor with.
Example:
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("val"), td.col("val").xor(8).alias("xor"))
>>>
┌─────┬─────┐
│ val ┆ xor │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 0 ┆ 8 │
│ 30 ┆ 22 │
│ 60 ┆ 52 │
│ 90 ┆ 82 │
└─────┴─────┘