默认情况下,rank通过“为各组分配一个平均排名”的方式来破坏平级关系
import pandas as pd
obj = pd.Series([7, -5, 7, 4, 2, 0, 4])
obj.rank()
method | |||||
index | val | average | min | max | first |
0 | 7 | 6.5 | 6.0 | 7.0 | 6.0 |
1 | -5 | 1.0 | 1.0 | 1.0 | 1.0 |
2 | 7 | 6.5 | 6.0 | 7.0 | 7.0 |
3 | 4 | 4.5 | 4.0 | 5.0 | 4.0 |
4 | 2 | 3.0 | 3.0 | 3.0 | 3.0 |
5 | 0 | 2.0 | 2.0 | 2.0 | 2.0 |
6 | 4 | 4.5 | 4.0 | 5.0 | 5.0 |
注:因为是float形式,所以有浮点
obj.rank(method='first')