torcharrow.DataFrame.sort¶
- DataFrame.sort(by: ty.Optional[ty.List[str]] = None, ascending=True, na_position: ty.Literal['last', 'first'] = 'last')¶
以升序或降序排列欄位/資料框架。
- 參數:
by (類似陣列, 預設值 None) – 要排序的欄位,如果為 None,則使用所有欄位進行比較。
ascending (布林值, 預設值 True) – 如果為 true,則以升序排列,否則以降序排列。
na_position ({{'last', 'first'}}, 預設值 "last") – 若為 ‘last’,則將空值排在非空值之後;若為 ‘first’,則將空值排在非空值之前。
範例
>>> 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