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