pandas sorting, ranking function --sort_index (), sort_values (), rank ()

1、sort_index()

 frame = pd.DataFrame({'a':[2.3,-1.7,5,3],'b':[6,2.9,-3.1,8]},index=['one','two','three','four'])

  For sorting by index, the index can be specified row or column index, by default sort row index (axis = 0): frame.sort_index (axis = 0)

Press column index (axis = 1): frame.sort_index (axis = 1), an optional parameter ascending, False descending, the default is ascending.

2、sort_values()

  Values ​​are sorted by the element can be specified by row or column, the default sorted rows (one or more columns), optional parameters by, axis, ascending, by a specified row or column index, axis shaft for designating, for Ascending designated liter descending order.

3、rank()

  The default row position (one or more columns), the default average ranking, using the average position of the same data as the ranking i.e. presence of the same data exists same level relationship, there are also optional parameters axis, ascending, method, breaking the same level relationship method, i.e. the method parameter options: average, min, max, first, dense. In particular, should pay attention to dense between 1 Rank always increases, it will not equal the number of elements in the group, which is different min.

Guess you like

Origin www.cnblogs.com/jason--/p/11427992.html