小型带有充分索引的 Series
In [28]: obj = pd.Series(range(5), index=['a', 'a', 'b', 'b', 'c'])
In [29]: obj
Out[29]:
a 0
a 1
b 2
b 3
c 4
dtype: int64
is_unique 属性告诉标签是否唯一
In [30]: obj.index.is_unique
Out[30]: False
In [31]: obj['a']
Out[31]:
a 0
a 1
DataFrame 中进行行索引
In [34]: df = pd.DataFrame(np.random.randn(4, 3), index=['a', 'a', 'b', 'b'])
In [35]: df
Out[35]:
0 1 2
a -1.174945 0.611333 2.096039
a -0.670033 -0.741968 -0.111807
b 1.086684 -0.608576 0.829530
b -0.532987 -0.794953 0.781699
In [36]: df.loc['b']
Out[36]:
0 1 2
b 1.086684 -0.608576 0.829530
b -0.532987 -0.794953 0.781699
网友评论