In [2]:
import numpy as np
from pandas import Series,DataFrame
import pandas as pd
In [4]:
ser1 = Series(range(3),index=['C','A','B'])
ser1
Out[4]:
C    0
A    1
B    2
dtype: int64
In [10]:
# indexで並べ替え
ser1.sort_index()
Out[10]:
A    1
B    2
C    0
dtype: int64
In [8]:
# 値で並べ替えももちろんできます。
ser1.order()
Out[8]:
C    0
A    1
B    2
dtype: int64
In [9]:
from numpy.random import randn
ser2 = Series(randn(10))
ser2
Out[9]:
0   -1.017907
1   -1.017797
2   -1.734658
3    0.532220
4   -0.007369
5   -0.295394
6   -0.634524
7    0.736754
8   -0.569379
9   -1.132936
dtype: float64
In [13]:
# 何番目に来るかを出せる。
ser2.rank()
Out[13]:
0     3
1     4
2     1
3     9
4     8
5     7
6     5
7    10
8     6
9     2
dtype: float64
In [14]:
ser2.sort()
ser2
Out[14]:
2   -1.734658
9   -1.132936
0   -1.017907
1   -1.017797
6   -0.634524
8   -0.569379
5   -0.295394
4   -0.007369
3    0.532220
7    0.736754
dtype: float64
In [15]:
# ソートされているので、ランクは順番通り。
ser2.rank()
Out[15]:
2     1
9     2
0     3
1     4
6     5
8     6
5     7
4     8
3     9
7    10
dtype: float64