tabsdata.tableframe.expr.expr.Expr.n_unique#
- Expr.n_unique() Expr [source]#
Aggregation operation that counts the unique values of the given column in the group.
Examples:
>>> 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 │ └──────┴─────┘