"With Python data analysis" --- pandas Start 2

pandas Started - Basic

Page 138

Sorting and ranking

The sorted data set conditions is an important built-in arithmetic. To sort the row or column index (lexicographic order) (a, b, c, d), may be used sort_index () method, it returns a new object is sorted:

 For DataFrame, can be sorted according to any one indexing axis:

 The default data is sorted in ascending order, but may be in descending order:

To sort by value of the Series, you can use it sort_values method (probably Seris object does not order attribute meaning, then I Baidu is not a bit, saying that after the release of Python3.6 order has no property, and try to use sort_values () method just fine.)

 When ordering, any missing default value will be placed at the end of the Series:

 On DataFrame, you may want to sort based on the values ​​of one or more columns. The one or more columns by name passed to the option to achieve this

 Rank (ranking) is closely related with the sort, and it will be the addition of a ranking value (starting with 1, until the number of valid data in the array).

Next comes Series and DataFrame the rank method. By default, rank by "average for the group is assigned a ranking," the same level way undermine relations

 They are ranked in descending order:

 DataFrame row or column can be calculated on the rankings:

Metho options for destroying same level relationship Ranking Table 5-8:
'Average': Default: equal in packets, each assigned a value average position

'Min': using a minimum rank of the entire packet

'Max': maximum rank entire packet

'First': assign rank order values ​​appear in the original data


 

Axis index with duplicate values

 While many pandas function (such as reindex) requires a unique label, but this is not mandatory. Let's look at a simple repetition of the Series with an index value of:

Is_unique property index can tell you whether its value is unique

 对于带有重复值的索引,数据选取的行为将会有些不同。如果索引对应多个值,则返回一个Series,而对应单个值的,则返回一个标量

对DataFrame的行进行索引时也是如此

 

Guess you like

Origin www.cnblogs.com/JasonPeng1/p/12118949.html
Recommended