Shortcuts

torcharrow.DataFrame.sort

DataFrame.sort(by: ty.Optional[ty.List[str]] = None, ascending=True, na_position: ty.Literal['last', 'first'] = 'last')

按升序或降序对列/数据框进行排序。

Parameters:
  • by (array-like, 默认 None) – 用于排序的列,如果为 None,则使用所有列进行比较。

  • ascending (bool, 默认 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