torcharrow.DataFrame.sort¶
- DataFrame.sort(by: ty.Optional[ty.List[str]] = None, ascending=True, na_position: ty.Literal['last', 'first'] = 'last')¶
Sort a column/a dataframe in ascending or descending order.
- Parameters:
by (array-like, default None) – Columns to sort by, uses all columns for comparison if None.
ascending (bool, default True) – If true, sort in ascending order, else descending.
na_position ({{'last', 'first'}}, default "last") – If ‘last’ order nulls after non-null values, if ‘first’ orders nulls before non-null values.
Examples
>>> import torcharrow as ta >>> df = ta.dataframe({'a': list(range(7)), >>> 'b': list(reversed(range(7))), >>> 'c': list(range(7)) >>> }) >>> df.sort(by=['c', 'b']).head(2) index a b c d ------- --- --- --- --- 0 0 6 0 99 1 1 5 1 100 dtype: Struct([Field('a', int64), Field('b', int64), Field('c', int64), Field('d', int64)]), count: 2, null_count: 0