tabsdata.tableframe.expr.expr.Expr.filter#

Expr.filter(*predicates: Expr | Series | str | Iterable[Expr | Series | str]) Expr[source]#

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:

predicates – Expression(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           │
└───────┴─────────────┘