2021-06-21

python中sort_values()的用法@TOC

sort_values()

首先先解释一下Dataframe中axis、index、column中的概念:

  • axis使用0值表示沿着每一列或行标签\索引值向下执行方法,默认为0;
  • axis使用1值表示沿着每一行或者列标签横向执行对应的方法;
    在这里插入图片描述

然后介绍参数:

pandas . DataFrame .sort_values = sort_values(self, by, axis=0, ascending=True, inplace=False, kind=‘quicksort’, na_position=‘last’, ignore_index=False, key: ‘ValueKeyFunc’ = None)

   ----------
        by : str or list of str
            Name or list of names to sort by.

**ascending** : bool or list of bool, default True
     Sort ascending vs. descending. Specify list for multiple sort
     orders.  If this is a list of bools, must match the length of
     the by.(布尔类型,true就是升序,false就是降序,默认为真。)
     
**inplace** : bool, default False
     If True, perform operation in-place.(布尔类型,默认是false,如果True立即执行运算)
     
**kind** : {'quicksort', 'mergesort', 'heapsort'}, default 'quicksort'
     Choice of sorting algorithm. See also ndarray.np.sort for more
     information.  `mergesort` is the only stable algorithm. For
     DataFrames, this option is only applied when sorting on a single
     column or label.
     ({'快速排序','合并排序','堆排序'},默认的'快速排序')
     
**na_position** : {'first', 'last'}, default 'last'
     Puts NaNs at the beginning if `first`; `last` puts NaNs at the
     end.(默认的“last”,如果“first”,则Nan放在开头,如果“last”则相反。)
     
**ignore_index** : bool, default False
     If True, the resulting axis will be labeled 0, 1, …, n - 1.
(默认的“false”,如果“true”,则axis被标记为0,1....n-1,如果“last”则相反。)
       
**key** : callable, optional
    Apply the key function to the values
    before sorting. This is similar to the `key` argument in the
    builtin :meth:`sorted` function, with the notable difference that
    this `key` function should be *vectorized*. It should expect a
    ``Series`` and return a Series with the same shape as the input.
    It will be applied to each column in `by` independently.

    .. versionadded:: 1.1.0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值