tabsdata.tableframe.lazyframe.frame.TableFrame.sort#

TableFrame.sort(by: td_expr.IntoExpr | Iterable[td_expr.IntoExpr], *more_by: td_expr.IntoExpr, descending: bool | Sequence[bool] = False, nulls_last: bool | Sequence[bool] = False, maintain_order: bool = False) TableFrame[source]#

Sort the TableFrame by the given column(s) or expression(s).

Parameters:
  • by – Column(s) or expression(s) to sort by.

  • more_by – Additional colums to sort by.

  • descending – Specifies if the sorting should be descending or not.

  • nulls_last – Specifies if null values should be placed last.

  • maintain_order – Preserve the order of equal rows.

Example:

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ a    ┆ b    │
│ ---  ┆ ---  │
│ str  ┆ i64  │
╞══════╪══════╡
│ A    ┆ 1    │
│ X    ┆ 10   │
│ C    ┆ 3    │
│ D    ┆ 5    │
│ M    ┆ 9    │
│ A    ┆ 100  │
│ M    ┆ 50   │
│ null ┆ 20   │
│ F    ┆ null │
└──────┴──────┘
>>>
>>> tf.sort(td.col("a"), descending = True)
>>>
┌──────┬───────┐
│ a    ┆ b     │
│ ---  ┆ ---   │
│ str  ┆ f32   │
╞══════╪═══════╡
│ A    ┆ 1.0   │
│ X    ┆ 10.0  │
│ C    ┆ 3.0   │
│ D    ┆ 5.0   │
│ M    ┆ 9.0   │
│ A    ┆ 100.0 │
│ M    ┆ 50.0  │
│ null ┆ 20.0  │
│ F    ┆ null  │
└──────┴───────┘