pandas 专栏收录该内容
82 篇文章 4 订阅

# 按值排序

DataFrame.sort_values(by, axis=0, ascending=True, inplace=False, kind=’quicksort’, na_position=’last’)

## 参数

by : str or list of str排序的列
axis : {0 or ‘index’, 1 or ‘columns’}, default 0排序的方向
ascending : bool or list of bool, default True升序或降序
inplace : bool, default False
kind : {‘quicksort’, ‘mergesort’, ‘heapsort’}, default ‘quicksort’选择排序算法
na_position : {‘first’, ‘last’}, default ‘last’空值排放的次序

df.sort_values([‘class’,‘score’],ascending=[1,0],inplace=True)

## 返回

1. sorted_obj : DataFrame

# 按索引排序

DataFrame.sort_index(axis=0, level=None, ascending=True, inplace=False, kind=’quicksort’, na_position=’last’, sort_remaining=True, by=None)

## 参数

axis : index, columns to direct sorting排序方向
level : int or level name or list of ints or list of level names索引level选择
ascending : boolean, default True
inplace : bool, default False
kind : {‘quicksort’, ‘mergesort’, ‘heapsort’}, default ‘quicksort’
na_position : {‘first’, ‘last’}, default ‘last’
sort_remaining : bool, default True

## 返回

1. sorted_obj : DataFrame

# 选取排序后的值

DataFrame.nlargest(n, columns, keep=’first’)
DataFrame.nsmallest(n, columns[, keep])

## 参数

n : int检索值的个数
columns : list or str排序列
keep : {‘first’, ‘last’, False}, default ‘first’Where there are duplicate values: - first : take the first occurrence. - last : take the last occurrence.
• 0
点赞
• 0
评论
• 2
收藏
• 扫一扫，分享海报

09-20
01-15 6756

02-16 7377
11-25 2万+
08-04 1833
04-17 1万+
10-23 5万+
05-03 3616