使用Pandas对数据进行筛选和排序
在Pandas中通过.sort和.loc函数也可以实现这两 个功能。.sort函数可以实现对数据表的排序操作;.loc函数可以实现对数据表的筛选操作。
对值进行排序
pandas.DataFrame.sort_values
-
Sort by the values along either axis
New in version 0.17.0.
Parameters: by : str or list of str
Name or list of names which refer to the axis items.
axis : {0 or ‘index’, 1 or ‘columns’}, default 0
Axis to direct sorting
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.
inplace : bool, default False
if True, perform operation in-place
kind : {‘quicksort’, ‘mergesort’, ‘heapsort’}, default ‘quicksort’
Choice of sorting algorithm. See also ndarray.np.sort for more information. mergesortis t
DataFrame.
sort_values
(
by,
axis=0,
ascending=True,
inplace=False,
kind='quicksort',
na_position='last'
)
[source]