dense_rank¶
- pydiverse.transform.dense_rank(
- *,
- partition_by: Col | ColName | str | Iterable[Col | ColName | str] | None = None,
- arrange: ColExpr | Iterable[ColExpr],
The number of smaller or equal values in the column (not counting duplicates).
This function has two syntax alternatives, as shown in the example below. The pdt. version is a bit more flexible, because it allows sorting by multiple expressions.
Examples
>>> t = pdt.Table({"a": [5, -1, 435, -1, 8, None, 8]}) >>> ( ... t ... >> mutate( ... x=t.a.nulls_first().dense_rank(), ... y=pdt.dense_rank(arrange=t.a.nulls_first()), ... ) ... >> show() ... ) Table <unnamed>, backend: PolarsImpl shape: (7, 3) ┌──────┬─────┬─────┐ │ a ┆ x ┆ y │ │ --- ┆ --- ┆ --- │ │ i64 ┆ i64 ┆ i64 │ ╞══════╪═════╪═════╡ │ 5 ┆ 3 ┆ 3 │ │ -1 ┆ 2 ┆ 2 │ │ 435 ┆ 5 ┆ 5 │ │ -1 ┆ 2 ┆ 2 │ │ 8 ┆ 4 ┆ 4 │ │ null ┆ 1 ┆ 1 │ │ 8 ┆ 4 ┆ 4 │ └──────┴─────┴─────┘