Expr.filter
methodView source ↗
def filter(*predicates: td_IntoExprColumn | Iterable[td_IntoExprColumn]) -> Expr
Categories: filters
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
parameter
predicatesExpression(s) that evaluates to a boolean.
Examples
>>> 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 │
└───────┴─────────────┘